I’m looking for the libraries and code samples for the single channel NCD Raspberry Pi 0-10V Board. And any other documentation would be great. I picked this board as the product page mentions Pi libraries and code samples but I cant find them.
the sample code can be found here
To convert ADC values into voltage values use this formula
Voltage = Raw_ADC*0.00034 ( to read 0-10V DC)
Does that relate to the single channel board and include outputting 0-10V rather than reading?
here is an arduino sample code
its a super easy chip. you can directly write the dac value to the chip.
Hi Bhaskar & JF,
I’m following along, with the same goal in mind.
I’ve tried to compile the code from both the read and write examples, but I’m still getting inconsistent readings when checking against a voltage meter.
Could you take a peak at my code so far and let me know where I might be going wrong?
Welcome to the community scroix,
This is kind of a strange chip. On most chips the standard packet would be [address, register, [value]] for a write. Usually the [value] is just a single byte that you want that register to be set at.
This is just [address, [value]] where value is a series of bytes to determine the voltage.
What you’re sending on line 36 is [address, register, [value]]. Try just bus. write_byte_data(DEVICE_ADDRESS, (raw_value >> 4), ((raw_value & 15) << 4)
let me know if that works. Also send over any error messages you’re getting.
Thank you, Jacob!
I’m happy to report that worked. In my example, I simply had to adjust the “offset” from 0x00 to 0x60 (the same as the device address).
bus.write_i2c_block_data(0x60, 0x60, [(raw_value >> 4), ((raw_value & 15) << 4)])
The value being a 12-bit number from 0-4095 which corresponds to 0-10v
The only trouble I have left is converting the data I’m getting back from the registers into voltage.
@Bhaskar gave me two examples that are listed as functions in my original code gist, convert_to_12bits(data) and convert_to_voltage(raw_adc).
The results I’m getting don’t seem right. For example, I’ve succesfully written 4095 to the register, and the multimedia is reading 10v, however reversing the process and reading 2 bytes from 0x60 with an offset 0x60 (or 0x00 for that matter) is producing the following results.
Raw Data: [192, 255]
Raw ADC Output: 255
Any thoughts would be much appreciated. All the registers are seeming to give me the same raw data.
Well, its been a minute since I last worked with these, but this one worked last I checked: https://github.com/ncd-io/MCP3428/tree/master/Python
It doesn’t have anything for setting an output on the MCP3428, but the read functions worked for me.
The register on that particular chip is different depending on the particular options with an OR operand self.mode | self.sample_rate | self.gain | (32*channel)