Category Archives: esp8266

Twitter for ESP 8266

I’ve been using the Wemos D1 Mini ESP 8266 for lots of projects, and I like it very much – being an ESP, it’s got wifi, you can use it straightforwardly with Arduino libraries, it has plenty of pins and uses USB micro rather than mini. Dirk introduced me to a nice library to make it broadcast an access point if it can’t get online. There are loads of D1 Minis on ebay.

I wanted to make a tweeting spatula for Jasmine because of her brilliant work on CAKE, the Cook Along Kitchen Experience. Seemed like the obvious thing to do. But Twitter uses OAuth 2.0, which is reasonably complicated and not many people want to code it, especially on such a constrained platform. Most people use some sort of IFTTT type mechanism, connecting accounts on the cloud side, or run a server-side proxy themselves to do the heavy lifting.

But four months ago, Soramimi wrote a twitter client for the ESP, including from-scratch implementations of base64 and sha1! It’s amazing. So that’s what I used. But I barely changed it, just adding the AP library and having it tweet when a gyroscope hit a particular threshold (using the Adafruit sensor library) rather than via a webpage.

img_6910

I used a small rechargable battery, and some cable webbing to cover it all in a handle  – Jon Tutcher’s idea 🙂

The wiring’s straightforward – here’s a picture from when I was moving from the plugged to a soldered version.

IMG_6903.JPG

I think maybe an accelerometer might work better – I’m going to try these cheapo ones from Pimoroni next. The only issue I really had (and it was annoying, but there we go) was that I kept running out of memory on the D1 because, it turned out, of this line:

  if(event.gyro.x > 0.7 && event.gyro.y > 0.7 && event.gyro.z > 0.7){

The error is:

[...]
../../../xtensa-lx106-elf/bin/ld: Gyro_ESP_Twitter.ino.elf section `.text' will not fit in region `iram1_0_seg'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board WeMos D1 R2 & mini.

I was convinced it was all the libraries I was using, but no. The line corrected to

 const float threshold = 0.7;
 if(event.gyro.x > threshold && event.gyro.y > threshold && event.gyro.z > threshold){

worked perfectly. I guess otherwise you get 3 x float created for every loop. Oops 🙂