Tutorial: ESP32 / BC24 and LSM303 Compass – Accelerometer
This is a project to demonstrate the capabilities of the BC24, LMS303 Compass and the ESP32. Once assembled and programmed, you can rotate the board and a Red LED will track magnetic north. The rest of the BC24 Pixel LEDs will show you when you tilt the board in any direction by changing colors. It’s really fun to watch. Video of the project is at the end.
Here is the video of the whole system working on our BC24.
What is the BC24?
The BC24 is a flexible way to display all sorts of data while being able to communicate with other devices and the Internet. It is a board that you can plug in your sensors and create new things!
The BC24 consists of three major parts:
1) Dual CPU ESP32 Central Processor with WiFi and Bluetooth
2) The 24 RGBW Programmable LED Pixel Circle
3) No Solder Grove Connectors for expansion!
The RGBW (Red Green Blue White) Pixels are completely programmable (millions of colors) and includes a bright white LED to give you pure warm white. These programmable pixels are 100% compatible with NeoPixels.
The Grove connectors allow you to easily and safely connect hundreds of sensors (and more Pixel strips if you want!) with no soldering. And you CAN’T plug them in backwards. Fewer boards in the Box of Death.
What is the LSM303?
The Grove 6-Axis Accelerometer&Compass is a 3-axis accelerometer combined with a 3-axis magnetic sensor. This board is based on the sensor module LSM303D which has a selectable linear acceleration full scale range of ±2g / ±4g / ±8g / ±16g and a selectable magnetic field full scale range of ±2 /±4 / ±8 / ±12 gauss. Both the magnetic parts and the accelerometer parts can be powered down separately to reduce the power consumption. The processor can get all of this data data via the I2C interface and can calculate numerous angles and headings from this data. The LSM303D is a system-in-package featuring a 3D digital linear acceleration sensor and a 3D digital magnetic sensor.
The board reports the 3 axes magnetic field and the 3 acceleration vectors.
What is the ESP32?
The ESP32 is an awesome processor. It has 2 CPU cores, lots of memory and has really interesting stuff built in like capacitive touch sensors, a Digital to Analog Converter (think Music out from your BC24!), lots of GPIO (General Purpose Input Output) for your projects and a robust I2C bus for connecting to your sensors.
Programmable with the Arduino IDE.
The LSM303 Compass and Accelerometer Project
You can buy the Grove 6 – Axis Accelerometer&Compass v2.0 here.
The Assembly is very easy. First, we connect the LSM303 Board Grove board using a Grove cable to one of the I2C ports on the back of the BC24 board. Remember that the I2C bus is a bus so you can use any one of the three ports on the back of the machine. Note in the above picture, we have put blue tape over the pins just to the right of the Compass. Always a good thing to cover things that might touch the Compass Board. Do this now.
Next, route the I2C cable up through the hole, and using tape, stick down the Compass board in the orientation shown.
If you are new to the ESP32, set up your Arduino IDE as in the Adafruit tutorial here.
Once you have that up and working, download the SDL_ESP32_BC24_COMPASS library. The install int your Arduino directory, compile and download it to the BC24 board.
If everything worked properly, you will see three red LEDS on the lower part of the BC24 board flash and then the system will turn all of the lights a light purple and you will see one Red LED pointing towards Magnetic North.