jbienzms / iot-devices

Helper library for interfacing with devices in IoT projects.
45 stars 17 forks source link

Possible bug in MCP3008 #13

Open ZingPow opened 6 years ago

ZingPow commented 6 years ago

I think there might be an issue in build the command to the MCP3008, plus I'd like to add a MCP3002. Is this the proper project to add this to as I've seen some other similar projects on GitHub (ie Glovebox) and I'd like to contribute to the proper one.

Foppotee commented 6 years ago

I am also having problems with MCP3008. Working to figure out how to debug where the issue is.

ZingPow commented 6 years ago

The bit banging is a little off for the 3008, this works for me.

if (channelMode == ProviderAdcChannelMode.Differential) { //leading bits changes depending on resolution of ADC int shiftLeftNum = 7; // 15 - 7 //shift the channel selection to be after start bit //and mode bit int channelShifter = 4; //13 //0x01 is 0001 in binary command = (UInt16)((0x2 << shiftLeftNum) //start bit + single bit ie 10 | ((Int16)channelNumber << channelShifter)); } else { //leading bits changes depending on resolution of ADC int shiftLeftNum = 7; // 15 - 7 //shift the channel selection to be after start bit //and mode bit int channelShifter = 4; // 13; //0x03 is 0011 in binary command = (UInt16)((0x03 << shiftLeftNum) //start bit + single bit ie 11 | ((Int16)channelNumber << channelShifter)); }

Foppotee commented 6 years ago

@ZingPow Do you mind sharing how you wired the MCP3008 to the Pi? (Assuming your using a Pi) I have tried both the Hardware and Software configs on https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters/mcp3008

ZingPow commented 6 years ago

I teach a hands on lab using the Raspberry Pi, a bunch of sensors and a MCP3008 and you can find the source code and Frtizing diagram (ie the wiring) here on my OneDrive

link to my OneDrive location for this lab

Hopefully this helps. I don't use this library in the lab as I wanted to keep it close to the chips so the attendees understand how this works.