About Takaitra

Matthew is a software engineer for Amazon's Cloud Drive team working with various technologies including web services, React Native and Android. His interests include motorcycling, camping, photography, small electronics and traveling. He lives in Seattle, Washington with his beautiful wife and two children.
View all posts by Takaitra →

11 thoughts on “Controlling an SPI device with the Raspberry Pi”

Hi, great instructions for someone like me who is in retirement years and just starting out with a rpi zero w. I don’t think I will have a problem getting the spi up and running, but after I get my information of my device, do you have any advise as how I can get that information into a node-red flow? I am trying to get the output of a max6675 thermocouple controller to the input of a nice gauge for showing the temperature of my kiln.

The middle “2 byte array” part confused me but for anyone else who is also confused here’s an explanation:
lets say we want to send the number 770 to the device (1100000010). The info needs to be sent in bytes(packages of 8 bits), and since the number is 10 bits long, we need to split it (into “11” and “00000010”).

To get the first part we need to use the “>>” bitwise operator.”>>” takes an integer and removes bits from that integer from the end as it is represented in binary. So 770>>8 removes the last 8 bits and leaves us with a 3 (11 in binary).

To get the 2nd part we need to use the “&” bitwise operator to leave us with the last 8 bits of our number. “&” takes two numbers, converts them to binary, compares the two, and outputs a resulting number where both bits are 1 for each position. An easy way to get only the last 8 bits of our number is to compare our number to a number that is 11111111 in binary (255 in integers or FF in hex)(0xFF = 255 in python, as does 0b11111111). So 770 & 0xFF gives us 2 (00000010 or 10 in binary)

Great little article … thanks, it was helpful. I wasn’t sure how to contact you other than writing this post to inform you of a mistake on your about blurb. Developer is mentioned twice. “a Java EE developer developer at Cargill, … “