iot-devices icon indicating copy to clipboard operation
iot-devices copied to clipboard

Possible bug in MCP3008

Open ZingPow opened this issue 7 years ago • 4 comments

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.

ZingPow avatar Dec 09 '17 07:12 ZingPow

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

Foppotee avatar Dec 23 '17 08:12 Foppotee

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)); }

ZingPow avatar Dec 23 '17 16:12 ZingPow

@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

Foppotee avatar Dec 23 '17 22:12 Foppotee

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.

ZingPow avatar Dec 24 '17 00:12 ZingPow