Hello, I am trying to get my picodev LIS3DH accelerometer (PiicoDev 3-Axis Accelerometer LIS3DH | Buy in Australia | CE08705 | Core Electronics) working with my Arduino Uno r3 and have run into a few issues regarding connecting to the sensor. I soldered the sensor to header pins myself and found that the address is 0x19 (from the datasheet.)
Here is a diagram of what my circuit looks like:
Hi Matthew
You have to connect the grounds of the level converter to the Arduino and LIS3DH. And 5V and 3.3V to the VHigh and VLow on the level converter. That is if the level converter is the type I think it probably is.
In other words you are missing 4 connections.
Cheers Bob
Hi Lia,
I’m using the “Adafruit testbed” library to scan my i2c and a similar issue to the previous one has come up. Here is the code that is found under the “examples” of the testbed library that I am using:
#include <Adafruit_TestBed.h>
extern Adafruit_TestBed TB;
#define DEFAULT_I2C_PORT &Wire
// Some boards have TWO I2C ports, how nifty. We should scan both
#if defined(ARDUINO_ARCH_RP2040) \
|| defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2) \
|| defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3_NOPSRAM) \
|| defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3) \
|| defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO) \
|| defined(ARDUINO_SAM_DUE) \
|| defined(ARDUINO_ARCH_RENESAS_UNO)
#define SECONDARY_I2C_PORT &Wire1
#endif
void setup() {
Serial.begin(115200);
// Wait for Serial port to open
while (!Serial) {
delay(10);
}
delay(500);
Serial.println("Adafruit I2C Scanner");
#if defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3_NOPSRAM) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO)
// ESP32 is kinda odd in that secondary ports must be manually
// assigned their pins with setPins()!
Wire1.setPins(SDA1, SCL1);
#endif
#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
// turn on the I2C power by setting pin to opposite of 'rest state'
pinMode(PIN_I2C_POWER, INPUT);
delay(1);
bool polarity = digitalRead(PIN_I2C_POWER);
pinMode(PIN_I2C_POWER, OUTPUT);
digitalWrite(PIN_I2C_POWER, !polarity);
#endif
#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2_TFT)
pinMode(TFT_I2C_POWER, OUTPUT);
digitalWrite(TFT_I2C_POWER, HIGH);
#endif
Here is the serial output:
Default port (Wire) I2C scan: Adafruit I2C Scanner
Default port (Wire) I2C scan:
It seems that part of this issue might be to do with the serial outputs, I double checked the baud rates of the code and my serial monitor and they are matching. To try and debug this I tried running some code that just prints hello once in the serial monitor:
void setup() {
Serial.begin(115200);
Serial.print("hello");
}
void loop() {
// put your main code here, to run repeatedly:
}
Here is the serial output:
hellohello
It seems that the serial monitor is definitely part of this issue.
The Adafruit Library example is for an SPI interface, the Adafruit product can use SPI or I2C, the PiicoDev is only for I2C. From a quick examination of the .h file the interface is determined by how to initialise the driver.
This line should do it Adafruit_LIS3DH lis = Adafruit_LIS3DH(); I think.
And it does look like something is amiss with the serial output.
I don’t have time to look into this further, but that is where I would start.
Cheers
Jim
EDIT: The three types of instances I listed are from Adafruit Circuit Playground. I found 2 libraries on my PC; Adafruit_LIS3DH and Adafruit_CPlay_LIS3DH. They are very similar with some differences, I would use the Adafruit_LIS3DH first; if this is the case on your PC.
That sort of result in the monitor indicates that the code is restarting. This can be caused by power supply problems - how are you powering the UNO? It can also be caused by major program errors such as addressing non-existent memory. Hardware faults are another possibility. What IDE are you using and how is it configured for the UNO? Have you tested this setup with any other sketches and what was the result?
Hi Matthew
Naughty naughty. When you are asking for help with diagnosing things which has to be done remotely ACCURACY is paramount.
When I saw your drawing I thought well that is a pretty good reason why nothing works.
No harm done this time as it only took about 10 minutes to decide “well that won’t work” and compose an answer but sometimes it can take days to prise the correct information out of a person.
Accuracy and as much information as you can provide usually yields quick results.
Cheers Bob
Good to see you have somewhere to start troubleshooting, let us know how it goes!
Regarding your original post, I love to see you including a diagram and code from the start, fantastic! As Bob said, it’s extremely important to make sure all the info you’re providing is correct, but at the end of the day, providing those things from the start helps us reach a quicker resolution!
For future, I recommend making block diagrams in a flow chart creator. My personal go-to is
It’s pretty standard, but allows for a lot more clarity in your diagrams. You could also use something like Fritzing to do this, but if the intent is a quick, simple, block diagram, I typically just use a flowchart designer.
Hello Jeff,
I’m powering my uno with a cable running from my usb port to the power/input area of my Arduino. I’m currently using IDE 3.3.3. I tried the SparkFunLIS3DH library and ran into some similar issues. I used the i2c example:
#include "SparkFunLIS3DH.h"
#include "Wire.h"
#include "SPI.h"
//Create two instances of the driver class
LIS3DH SensorOne( I2C_MODE, 0x19 );
LIS3DH SensorTwo( I2C_MODE, 0x18 );
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
//Call .begin() to configure the IMUs
if( SensorOne.begin() != 0 )
{
Serial.println("Problem starting the sensor at 0x19.");
}
else
{
Serial.println("Sensor at 0x19 started.");
}
if( SensorTwo.begin() != 0 )
{
Serial.println("Problem starting the sensor at 0x18.");
}
else
{
Serial.println("Sensor at 0x18 started.");
}
}
Here was the output:
Processor came out of reset.
Processor came out of reset.
The most recent Arduino IDE is 2.3.3: is that the one you mean? If so it is unlikely to be the direct cause of the problems. It is possible that if you have not configured the board manager properly and the IDE does not detect the error then it might execute invalid code and cause the restart, so check that you have selected the correct board for your MCU.
The other possible cause of that type of restarting is that the watchdog timer is not getting reset regularly. However AFAIK it is not running by default, and I can’t see that any of the code you are using is would start it for you, so that is not likely to be the issue. If it was the watchdog timer then it would indicate that your code is hung up somewhere.
The most likely cause of the restarts is that the USB port you are using cannot supply enough current to power the UNO, the LIS3DH and the level converter. You will get a clue to this possibility if you run a simple sketch on the UNO with nothing else connected. If that works, then try the same sketch with the other bits connected and see what happens. The blink example is suitable, with the extra code in Setup to print a message to tell you whether it is restarting and re-running Setup, or just looping in the main loop like it should. If that doesn’t work then it’s possible that the port does not have enough power for the UNO on its own, although I would think that unlikely, unless you are using a very poor cable. In that case you should source a separate 9V supply and provide that to the barrel jack on the UNO. You can have both the USB cable and the separate supply connected at the same time.
Hello Jeff,
I removed the logic level shifter and the LIS3DH from my circuit and ran the code. This time it worked (of course it printed “Couldnt start” because there is no circuit attached.) I’ll try adding a 9V power supply to help fix this issue and let you know how it goes. Just so I know what to look for next time when debugging could you please tell me why a lack of power caused these issues? Thank you very much!!!
Hi Jeff, I added a 9V battery to my Arduino (the battery definitely works as when I removed the usb my arduino was still powered.) Unfortunately, it still returns the: LIS3DH tesLIS3DH test!
To be clear - it printed “Couldn’t start” after printing “LIS3DH test!” without the stuttering? If so, that test has eliminated any configuration problem with the board manager and any possibility of the code doing something illegal and causing the reboot.
When the MCU detects that the supply voltage is too low it turns off. When it turns off it reduces the load on the power supply, so the voltage recovers. That causes the MCU to restart. Sometimes that cycle goes on forever, sometimes it stops after several cycles.
The 9V supply should have helped if the UNO was the problem, but the level shifter and LIS3DH are hanging off the 3V3 regulator, and the increased supply to that regulator will have only a small effect on the capability of that supply. So my guess is that either the level shifter or the LIS3DH is loading the 3V3 supply very heavily.
Firstly, do a very thorough examination of the pins and soldering of the level shifter and LIS3DH. Use a good magnifying glass and a bright light. Scrape between the pins with a blade or needle in case some flux is hiding a solder whisker.
Then try with only the UNO and the level shifter 5V+/- connected, then add the 5V connections between the level shifter and the UNO, then add the 3v3+/- from the UNO to the level shifter, then add the 3V3+/- the LIS3DH (without the data connections). That covers all other possible combinations, and should reveal where the problem is occurring.
Hello Jeff, I’ll trial out the debugging steps that you suggested and come back with any results. Thank you very much for all the time you’ve put in to helping me, I really appreciate it!
Hi Jeff
If that 9V battery Matthew used is of the little block type do you think it would have enough grunt to drive all that load. I don’t know off the top of my head just what the capability of one of those is and I just don’t have the time this minute to research it but I personally would have some doubts.
Cheers Bob