Introduction: ESP32 WEMOS LOLIN AND ADXL345
For those of you out there playing with the Wemos 32 LOLIN board I thought i would start to document some findings of mine so far.
Current project is to interface to an ADXL345 accelerometer and as the photo shows above i have successfully connected it to the lolin and configured the ADXL as a shock sensor.
The registers on the ADXL have been set up as the attached pdf and the interrupt i have configured in the code to spit out the code on the serial port once a shock is detected.
I also set up the inactivity register as an interrupt and after checking which interrupt has been triggered then spit out the same data.
I am using the I2c port on the LOLIN and you will see i have a routine to spit out the registers on the ADXL so i can check the config while debugging. This function is running in a timer function using the ticker library.
This is a useful function to set up for debugging and checking the registers in case you write something in there which mysteriously causes the data to do some strange things.
I have normalised the 2's compliment data in the LOLIN and formatted it so it can be imported into excel.
Have a look at teh attached PDF with some data i have imported and i have graphed in excel showing some taps on the ADXL which are triggered by an interrupt in the trigger register using FIFO mode.
FIFO mode is a useful feature which does not tie the micro up and it stores 32 samples on a trigger.
Again look at my data dumps and you can see where we start at ground zero and the last sample is at 9.8ms or there about.
X line on the graph shows the timing in microsecs increasing left to right.
NOTE I HAVE SINCE AMENDED THE LAST GRAPH TO SHOW TIMELINE FROM MINUS 9800 microsecs.
First pop of FIFO is the earliest data the rest is older.View should be from right to left.
Note the three wires to the ADXL board. SDA/SCL and the INT from INT 1. Again if you look at the register settings and cross ref the data sheet it will make sense.
Data sample is full tilt at 3200 samples which gives 3125 useconds between samples.and a pre capture of 4 samples. Look at the pdf of the data from the device in excel and each of the graphs i have plotted showing me moving the window of capture.
I will put up some code of the config and interrupts if anyone is interested.
For I2C i am using the wire library and have written some functions around that.
Notice the little data sniffer which i have connected to SDA/SDL and using Sigrok i can decode the I2C bus in real time.
Next step is to save to SAN disk although i have already proved it works. Once that is done I will interface to the wireless and upload to a website.
I will add to this as the project expands.
For the observant ones out there you will notice a large dent in the can protecting the esp chip and a jumper on the pcb. This has been due to the resident Cocker Spaniel who inspected the mail and decided to chew the board before letting me have access to it. I think she is a non espressif fan!.
Of course as always i am always up for questions so please ask.
Step 1: SIGROK AND PULSEVIEW
Just a quick mention of pulseview and sigrok.
This is free software from the net and the little interface board with 8 logic inputs is cheap from ebay et al.
You will notice a couple of images i grabbed off the bus while the ADXL was running and it is so useful again for debugging as it has a built in decoder for I2C.
A scope is great for checking signal levels but hand decoding of I2c is tiresome at best although i have set up a loop before now and hand debugged. You have to have an appreciation of bit banging at teh port level which i have done on many pic projects but it is time consuming and prone to errors...especially at night!!
Thanks to the guys who wrote this app. Its a god send for projects in i2c,
Note the D4 line which is monitoring the interrupt line from the ADXL.
Step 2: Adding to the Shock Sensor
Ok here i have added some peripherals to the shock sensor for proof of concept.
Excuse the rats nest for now once it works i'll design the pcb that links all components and put it all into a pretty box. All the items attached except the SD card are working on i2c which is on the spi bus.
Left to attach is the GPS module which is WIP but i hope to have a solution by the end of this week.
So current project consists of:
ESP32 LOLIN board with wireless.
PCF real time clock .Keeps track of current date and time. I have rough soldered onto an old project board i have etched previously.
External flash. Holds setup data for Accelerometer amongst other things.Capacity 132k and may dump some web data on it to facilitate menus etc
SPI SD card for storing file accelerometer data and logs. 8 GB but can expand.
OLED display to show menus and a few other things.
Here is what it will [eventually] do
Monitor shocks and activity that exceed background.
Register the shocks to SD card with time and date from onboard clock.
Stamp the location from GPS to SD card if avail
Using an access point upload the data to a web server to analyse the data...this can be a mobile phone.
|Scanning for access points is an ability of the LOLIN32 as is hosting a web server for commands and then connecting as a client to the cloud webserver. You can always just unplug the sd card and upload that!
Still lots to do but its moving on.
Step 3: ADXL ADDRESSING
Now here is a funny thing.
I purchased the ADXL 345 chip as a little board coz it was cheaper than sourcing a chip on its own.....how does that work? Anyway after that i set about hooking it up to the i2c bus and found i had a clash with the eeprom with addresses which effectively start at 0x53 which translates to a write at A6 and a read at A7.
So reading the bumf it turns out that if you take the SDO/ALT ADDRESS HIGH you can force it to 1D
Turns out that my little board is hardwired to ground on pin 12 of the ADXL despite the SDO pin which looks like you can pull it high. Dont try this at home without a current limited power supply....luckily i had which caused me to take out the multimeter and check the pin to ground.[Dead short] which means you have to cut the track and jumper pin 12 to 3.3v. This works and get you out of the prom clash.Luckily they did not do the short under the chip or else i would have been snookered and had to remove the chip from the board.
The EEprom which is a spare one i had is arranged as two pages of 64k as address 0x52 and 53. Once i did this my problem was solved.
Reading the web page again it does say its set to 0x53 but its in the small print so watch out!
We have a be nice policy.
Please be positive and constructive.