-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This does not seem to work when using the ESP32 #3
Comments
Will check tomorrow, too busy today. |
I'm using the MCP3002 |
There is any reason to force to use the default SPI port? Some boards like Arduino Mega or the ESP32 have more than one SPI port. I found this file and can be changed easy to work with the VSPI: But I think that can be better to use the SPI as an object, for example on this topic they talk about it: Maybe a easy way to implement is using something like this example and a single preprocessor define (by default uses the SPI like now and when we define something will use the vspi/hspi alternative): If you like the idea I can help to debug with a ESP32 and the MCP3008. |
The reason for the default SPI port? It is a starting point. First get something working and add functionality in small steps. |
(my agenda filled up with priority things so expect delay's) Problem 1: measurement too lowYou state you get only half the value expected with channel 0. Can you tell more about your measurement setup?
Can you make 3 measurements with channel 0 ?
The MCP3002 is a 10 bit so some of the expected values are - there might be noise
When using 5V to power the MCP3002 (= reference voltage) these numbers will be different. |
(found some time) 5V ==> 1021-1023 as expected => note more noise than expected. Powering the MCP3008 with 3V3 gave the following results: So although not tested with ESP32, the library acts like it should. Please note that the actual reading is affected (~33%) by the value of the (VDD/) Vref pin. |
@intakenick any luck getting good readings from this? I have an MCP3208 connected to an ESP32 and my values are low as well. I have a simple photoresistor hooked up to channel 0 and I see a range from 255-1250 on the MCP3208 with this lib and 850-4096 on the ESP32 ADC. I haven't had any luck with any other libraries working at all. |
I had some luck using the MCP3XXX library by Chris Baker. I had to lower
the SPI frequency within the h file to get more accurate results.
Line 278: typedef MCP3XXX_<10, 2, 1200000, 2> MCP3002;
I changed 1200000 (1.2MHz) to 100000 (100kHz) which is plenty fast enough
for my application. Results get more accurate with longer sampling time,
I've gone down as low as 10000.
Hope this helps.
…-N
--
Nick Johnson
Intake
(914) 906-3527 [mobile]
***@***.***
------------------------------------------------------------------------------------------------
Automating preventive care. (myintakepro.com)
NOTICE OF TRANSMISSION: This email and any files transmitted with it are
confidential and intended solely for the use of the individual or entity to
whom they are addressed. If you are not the named addressee please notify
the sender immediately and delete this e-mail from your system. If you are
not the intended recipient you are notified that disclosing, copying,
distributing or taking any action in reliance on the contents of this
information is strictly prohibited.
On Wed, Mar 10, 2021, 4:09 PM Boots ***@***.***> wrote:
@intakenick <https://github.com/intakenick> any luck getting good
readings from this? I have an MCP3208 connected to an ESP32 and my values
are low as well. I have a simple photoresistor hooked up to channel 0 and I
see a range from 255-1250 on the MCP3208 with this lib and 850-4096 on the
ESP32 ADC. I haven't had any luck with any other libraries working at all.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARBUKBBSCZ3H4YYQCZ5OHCLTC7GWDANCNFSM4X4YMHTQ>
.
|
@intakenick I definitely need find some time to verify / test. |
I ended up using a different library to prototype with but I'm going to revisit this one when my final boards are complete as it seems to be the most actively maintained 👍 |
I broke up my agenda and planned to run some tests tomorrow with ESP32 |
Do not have a working setup yet, but found a probable cause for the MCP3002 The buildRequest is not correct (line 132 in .cpp file) can you please check if this improves the measurement? uint8_t MCP3002::buildRequest(uint8_t channel, bool single, uint8_t * data)
{
// P17 fig 6.1 MCP3002
data[0] = 0x44; // start bit + MSB first bit
if (single) data[0] |= 0x20; // single read | differential
if (channel) data[0] |= (channel << 4); // channel = 0 or 1;
return 2;
} |
Got the MCP3008 working with software SPI
MCP3008 mcp1(23, 19, 21); // dataIn, datOut, Clock Read takes < 15ms |
@RobTillaart I have the MCP3208 (12 bit version) .. will your changes affect that? |
The changes posted above with the OR fix is only for the MCP3002. |
@RobTillaart Appreciate the work! I'll test the 3208 when ready. |
A review showed that the bit pattern created in the buildRequest() for the MCP3208 is good. Can you verify that the software SPI modus is working correctly? Created a branch named: ESP32demo with the fix for the mcp3002 and 2 demo sketches specific for the ESP32. The ESP32 software SPI is working correctly with the MPC3008 , |
For reference, I seem to get good values using hardware SPI and this library: |
Thanks, I'll have a look if they reduce the speed somehow (which is my assumption) |
Yep, labfruits use 1.6 MHz, I use 16MHz, 8 MHz fails, and it misses bits resulting in lower values. I will update my ESP32 hardware SPI example with a extra line to setSPISpeed() |
Good find 👍 |
Updated ESP32demo branch with working HW SPI @ 4 MHz |
Just merged it? Branch disappeared before I could pull it. Going to test now :) |
ESP32demo branch is merged and version 0.1.4 is released. |
@RobTillaart the values I'm reading now line up with the values I was getting using the labfruits library. Thanks for the fixes! |
Good to hear! |
If you are missing things in this or one of my other libraries (or missing a library at all) just let me know |
Can you confirm it works now for you too? |
If problem reappears please reopen issue. |
First off, thanks for sharing this! I'm having a few issues:
When reading from channel 0, the results are exactly 1/2 of what I'm measuring on my scope. This does not change if I alter the SPI frequency
When reading from channel 1, it always returns zero.
Using other libs for this chip, I always get skewed values, this has been most consistent despite still not providing the expected values. Any help is greatly appreciated.
The text was updated successfully, but these errors were encountered: