I am trying to read data via SPI from an ozone sensor that I have connected to the Raspberry Pi's GPIO. This set up uses a Mikro Pi click shield and Mikro Ozone 2 click sensor. The output of the sensor is analog, so an ADC has been included.
The ADC model is the single-channel, 22-bit MCP3551, which does not appear to be that common. I have written the below python code using this example, which thankfully works and reads the data from the ADC via SPI in 3-byte 'chunks'. This appears to be the only example on the internet in python for this ADC.
import spidev import time spi = spidev.SpiDev() spi.open(0, 0) spi.mode = 0b11 #spi.max_speed_hz = 1000000 try: while True: resp = spi.readbytes(3) if (resp != 255): print(resp) #value = 256*resp + resp value = resp + resp print(value) byte1 = bin(resp)[2:].rjust(8,'0') byte2 = bin(resp)[2:].rjust(8,'0') byte3 = bin(resp)[2:].rjust(8,'0') bits = byte1 + byte2 + byte3 print(byte) time.sleep(0.1) except KeyboardInterrupt: spi.close()
bits variable is a concatenation of the three bytes, so that I can see the 24 bits in a row. However, looking at the MCP3551 data sheet, I cannot work out how to interpret these bits and get a value (ideally a voltage). It seems the three bytes make up a 22-bit reading with 2 overflow bits.
I've tried to provide all the information I can, but I am a beginner in this area so apologies if I have missed anything. Any help would be much appreciated. Thanks!
Edit - the three bytes received are shown below in the square brackets:
[1, 3, 252]
[1, 3, 3]
[1, 3, 10]
[1, 3, 16]
[1, 3, 23]
[1, 3, 28]