Raspberry Pi 0-10V Board - libraries and code samples

#1

Hi

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.

Jules

0 Likes

#2

Hi Jules,
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)

Thanks

0 Likes

#3

Thank you
Does that relate to the single channel board and include outputting 0-10V rather than reading?

Cheers
JF

0 Likes

#4

here is an arduino sample code


its a super easy chip. you can directly write the dac value to the chip.

0 Likes

#5

Thank you very much!

0 Likes

#6

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.

https://gist.github.com/scroix/0acf6c900d0907db1749f7b54e7e74e2

Could you take a peak at my code so far and let me know where I might be going wrong?

Cheers,

scroix

0 Likes

#7

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.

1 Like

Cannot communicate with MCP4725 with smbus or Adafruit_MCP4725 library
MCP4725 and INP12 rev c on raspberry pi 3B+
#8

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).

For reference:

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

0 Likes

#9

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
Voltage:: 0.09V

Any thoughts would be much appreciated. All the registers are seeming to give me the same raw data.

0 Likes

#10

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)

0 Likes