I want to read the acceleration in the LSM9DS1 module from Arduino 33 BLE. This task is easy with the Arduino_LSM9DS1.h library but want to learn how Wire.h works properly. This is the last step of my objectives but I can't seem to get it running.
I converted the library in the last reply but I can't seem to get it working.
You may be overthinking this…
Check the code size when you use the library…
Only the functions you call, or are needed by the library will be compiled - unless they are specifically forced by the linker.
Impossible. Please take some time to formulate an exact description.
I don't know how register addressing is done on that IC. You must know, so how about some insights from you? Is is strictly sequential, or can you address individual registers?
I now understand how to read the third byte, thanks!
The code compiles and uploads it to Arduino, however, when I have the read function like this I can't open the Serial Monitor after uploading, it's my first time working with wire.h so I'm not exactly sure what is causing this. The port just disconnects and I have to reset the Arduino.
You can start by calling Wire.begin() in the setup() function and never call Wire.end().
You don't have to #include <Arduino.h> Please remove that.
Wire.begin() assigns certain pins to SDA and SCL and sets the hardware and software into I2C mode.
Wire.end() releases those pins and the software, so those pins can be used for something else. No one uses that, but it might be needed very rarely in some situations.
Can you start with a simple I2C sensor ? Do you have other I2C modules ?
Which Arduino board do you use and which sensor module ? I want to know if you have a 5V board with a 3.3V sensor without level shifter for SDA and SCL.
Have you tried to run a I2C Scanner sketch ? That is the first step. Can you show the output to us ?
The next step is reading the WHO_AM_I and the WHO_AM_I_M register. Can you show a sketch that does that ?
I'm having some trouble getting the error codes with arduino.
I only have an Arduino 33 BLE Sense, that's why I I'm using this example. The Module is the LSM9DS1 accelerometer in the Arduino platform. It runs fine using the library but not using this code.
Do I need to run the scanner even when the module is in the Arduino itself?
I ran one and it didn't found any device.
I am more familiar with the Wire functions but now I can't even run this code.
Yes, you need to run a I2C Scanner sketch. Then you know that the I2C bus is working. Use the newest Arduino IDE with all the updates for the boards and the libraries.
I remember vaguely that someone had troubles with a Portenta and a I2C Scanner that did not see any I2C devices, it might have to do that the Arduino software layer is based on Mbed. Your Arduino Nano 33 BLE Sense also based on Mbed.
The port should not disconnect. Can you try with a other USB cable and other USB port ?
Can you buy a other Arduino board ? I don't know what is going on
That means the I2C Scanner conflict with Mbed has not been solved yet
Can you keep that working sketch and try to add your own code to that ? Try to read those WHO_AM_I and WHO_AM_I_M registers in the loop(). Show your new sketch.
If you want to know how the Wire.h Library works, then connect two Arduinos together using I2C bus and play with register level codes. You will discover soon that the Wire.h Library just contains the same codes in the High Level Format which hides all the Register Level details from the users.
If it does not work, go back to the example that did work, and use the functions of the Wire library to get the two WHO_AM_I and WHO_AM_I_M bytes.
Every time that it stops working, go back to the example. I think you are throwing away too much. For example this:
while (!Serial);
Serial.println("Started");
The function "readRegister()" is part of the LSM9DS1 library. I thought you wanted to use the Arduino Wire library ?