esp8266_bitseq
esp8266_bitseq copied to clipboard
General purpose synchronized bit sampler for esp8266
#esp8266_bitseq
General purpose synchronized bit sampler for esp8266.
You can often find a hidden serial interface on your gadgets, it is used for in-factory testing and to sell you overpriced 'addons' with very limited functionality.
This library you can help you sample that data and do whatever you like with it.
This is how the caliper sends data: one channel for the clock pulses and another for the data.
These packages are usually separated by an idle period and then repeated. What this library does is to sample each databit at rising or falling clock pulse into a cyclic buffer. When it has aquired enough bits (configurable) and detected an idle period it will send your code a callback so that the data can be parsed and used.
I've added examples where i connect a cheap digital caliper, a digital dial and a power plug energy meter to a mqtt message broker.
Digital Caliper (wiki)
.
The main inspiration for this sampler was this blog.
Digital Dial (wiki)

Justin R. wrote a really useful blog about the digital dial that helped me a lot (no code though).
Power plug energy meter (wiki)

The energy meter is described in [Kalle Löfgrens blog] (http://gizmosnack.blogspot.se/2014/10/power-plug-energy-meter-hack.html). Just be aware that there is 50% chance that the logic wires (including GND) in that power meter will be directly connected to 230V. Don't even open the case if you don't know what you are doing. The LCD in the image is a Nokia 5110 LCD connected to another mqtt-enabled esp8266. Find the lcd project here.
Default pin configuration
| Device | ESP8266 |
|---|---|
| Clock | GPIO0 |
| Data | GPIO2 |
GPIO0 and GPIO2 is selected because of the ESP-1, but if you have more GPIO pins you can easily change the pin configuration to whatever you need (it's just a #define in user_config.h).
License
GNU GENERAL PUBLIC LICENSE Version 3
The makefile is copied from esp_mqtt.
###Building and installing:
First you need to install the sdk and the easy way of doing that is to use esp_open_sdk.
You can put that anywhere you like (/opt/local/esp-open-sdk, /esptools etc etc)
Then you could create a small setenv.sh file, containing the location of your newly compiled sdk and other platform specific info;
export SDK_BASE=/opt/local/esp-open-sdk/sdk
export PATH=${SDK_BASE}/../xtensa-lx106-elf/bin:${PATH}
export ESPPORT=/dev/ttyO0
(or setup your IDE to do the same)
To make a clean build, flash and connect to the esp console you just do this in a shell:
source setenv.sh # This is only needed once per session
make clean && make test
You won't be needing esptool, the makefile only uses esptool.py (provided by esp_open_sdk)
I have tested this with sdk v0.9.5 and v0.9.4 (linux & mac)