Talking to Twitter using TwitterWebAPI for ESP8266

Idea: Use ESP8266 to talk to Twitter Get User Data or Tweet or Search Twitter Display the data on a Dot-Matrix display Implementation: I created an Arduino library to talk to Twitter using its Web API made for ESP8266. There are other approaches like using a bearer token arduino-twitter-api, but comes with limitations in terms of not being able to send tweet. This Arduino library TwitterWebAPI can both search/read and post tweets. All the instructions and usage of library is described on my GitHub library page

Internet Connected Smoke Alarm

Idea: If there is smoke, smoke alarm detects it ESP8266 detects this digital signal from smoke detector, connects to WiFi and sends data to a MQTT server Esp8266 turns itself OFF Implementation: Try to find where on the smoke detector is the 3.3V digital signal when it detects smoke Lets look at Kiddie RF-SM-DC Third pin from top corner seems to send out 3.3V signal to speaker when it detects smoke Lets connect our previously created ESP8266 circuit that wakes from external interrupt. Configure Home Assistant to process MQTT message and send notifications. Source code for this idea can be found on my GitHub:

Extreme Power Saving of ESP8266 using External Interupt

Idea: Keep ESP8266 on OFF mode as default External 3.3V signal (can be short or long) arrives and turns ON ESP8266 ESP8266 wakes up and keeps itself awake until a task is perfomed Send MQTT data to server Put ESP8266 back to power OFF state Implementation: ESP8266 is in OFF state, GPIO0 is low 3.3V signal arrives externally, GPIO0 and CH_PD are high, turn ON ESP8266 First thing ESP8266 does is turns GPIO0 to high, which means CH_PD remain high. So ESP8266 remains ON until GPIO0 is high GPIO12 is used to read value of external interupt If there is 3.3V external interrupt, GPIO is high and a MQTT message is sent as “Signal Received” or “ON” and keep ESP8266 ON until 0V signal is received. If there is 0V external interrupt, GPIO0 goes low and MQTT message is sent as “Signal Vanished” or “OFF” and turns OFF ESP8266 Source code for this idea can be found on my GitHub This circuit diagram has been derived from here.

Internet Connected Water Bowl Sensor

Wouldn’t it be nice to know if your dog’s water bowl is empty? Let us build a sensor that measures the water level every 5 minutes. This value is sent to MQTT server and Home Assistant automation takes care of the rest. This sensor connects to MQTT and Home Assistant. See dogsensor.yaml for adding this to HA. Assumes that one has set up various notification sensors available in HA. Things needed: 3D Printed Case 18650 Battery ESP8266 12E Rain Water Level Sensor Arduino Code Github:

MOSFET used as switch to control a 12V Fan

Lets turn on and off low powered fan running at low (<20V) DC voltages. We shall use a MOSFET to achieve this. MOSFETs have three terminals Drain (D), Source (S) and Gate (G), where source is connected to ground and the +12V or +5V along with load (Fan) is connected to drain. The MOSFET is on when gate voltage is higher than 1.7V and turned off when gate voltage is 0V. This signal can be given out from a micro-controller as 3.3V/5V or 0V signals.

Twitter Mentions on a Dot-Matrix Display

Let’s say that you don’t have your smartphone around and someone mentions you on twitter. Wouldn’t it be nice to have a display that automatically reads your twitter mentions and show it on a scrolling display? So let’s build a internet controlled (IoT) dot-matrix display that does this for us using an ESP8266. The plan to accomplish this is as follows: Someone mentions us on twitter (in my case @debsahu) IF This Then That (IFTTT) tracks these mentions and posts this data on (MQTT Broker) An ESP8266 connects to and shows this data on a Dot-Matrix display We can’t control who mentions us on twitter, so we move to the second step in our plan to configure IFTTT and To setup a data feed (MQTT topic) on, Goto “feed” and “Create New Feed” Provide a unique name for the feed like “twitter-calls”, this means the MQTT topic that we need to subscribe to is “feed/twitter-calls” To setup IFTTT to connect to twitter and, Connect your twitter and account to IFTTT by logging in and giving proper permissions Create a new applet For “this“: Select “twitter” and “New mention of you” For “that“: Select “Adafruit” and “Send data to”. Remember to select the correct topic created above and a message template using ingredients that suits your need. As a part of the third step in our plan, we need to subscribe to our MQTT topic and display this data on a Dot-Matrix display. Hardware Wemos D1 mini (ESP8266) link Max7219 Dot Matrix Display here Software Setup Arduino IDE to be able to program an ESP8266 (Instructions on how to do this is here as well as in the video below). Install Adafruit_MQTT and MAX7219 Dot-Matrix display libraries Upload the code found here on your ESP8266 Make these following connections between Max 7219 display and Wemos D1: VCC -> 5V GND -> GND DIN -> D7 CS -> D8 CLK -> D5 That’s it, now you should be able to see your latest twitter mentions on your Dot-Matrix displays.

Internet of Things (IoT)

Building electronics is one of my hobbies and I have in the recent year developed this skill to a point that I can help inspire others to make these things that make our day to day activities easier. Activities as simple as turning on and off lights using the internet (or using voice via siri/alexa/google voice) will help save energy and make our lives more easy aka… automated. My MCU of choice will be ESP8266 which costs as low as $3 which operates at 80 MHz, equipped with WiFi and up to 8 GPIO pins. I own a few NodeMCU v1.0 and Wemos D1 mini that I will use for almost all of my projects. I have a tons of ESP8266 (micro-processors with WiFi capability), relays, displays, motion sensors, led strips etc that I can assemble to make a functional product. There will be two aspects to this, Hardware building encompassing soldering and planning circuits Software (Arduino IDE) to take care of all this hardware functioning properly. I will spare some time and build one product at a time, documenting it by videos and post the details over here. Some project examples will be something in the lines of internet controlled light switch or motion sensor based home automation or home security using laser trap or animations on a LED strip etc.

Converting NMR Pulses represented as kHz to usable format in Bruker Topspin 3+

Researchers tend to use the units of kHz to represent the power of decoupling or shaped pulses in research papers. The reason for the use of this unit is to easily transfer the pulse-widths & power-levels used in the experiment from one spectrometer to another, as one can back calculate the pulse-widths & power-levels as described below. The pulse frequency that is described here (in Hz) is the precession frequency about the magnetic field experienced due to the pulse in the rotating frame. This is not the frequency of pulse (B0), so please don’t confuse with this value. The flip angle of any given pulse is given by Where τα is the duration of the pulse to cause the flip angle α, with B1 being the magnitude of the magnetic field caused in the rotating frame. But the precession frequency(Hz) is defined as Solving for B1 will result in And for a 90° flip angle we can substitute α=90 or π/2, we get For example, a 25 kHz decoupling pulse would have a 90° flip angle of 10 µs. Now that we know how long the pulse need to be applied, we still need to figure out the power level for this pulse. Assuming a linear amplifier, we use the following equation for determining the unknown power level, So if a calibrated pulse of 7 µs at -9.6 dB is known, a 25 kHz (ie 10 µs pulse) would require -6.5 dB power level to flip desired magnetization by 90°.

Splitting Pseudo-3D experiments into series of 2Ds in Topspin 3+

Interleaved experiments are easy to run as pseudo 3D experiments. A detailed method to design NMR experiments in Topspin 3+ is described previously. While running the experiments or after the run the user may have to split the data into their respective 2Ds to evaluate the results. This can be done easily by using “xfb” command along with right dimensions (13 or 23) as input in Topspin or NMRPipe processing scripts to process 3D datasets. Alternatively one might split these pseudo-3D data into individual 2Ds using Topspin 3+ macros. If the user has designed pseudo 3Ds with F2 dimension to be used to loop through the loop-counter values one could use these following lines as Topspin macro. Remember to place the macro in $PATH_TOPSPIN/exp/stan/nmr/au/src/user (The following script is called “splitrelax13”) int td, texpno=1000; GETCURDATA GETINT(“Enter the first target expno: “,texpno) FETCHPAR1S(“TD”,&td) i1=0; TIMES(td) RSER2D(13, i1+1,i1+texpno) i1 ++; END QUITMSG(“— splitrelax13 finished —“) This script will automatically read the number of 2D files to split the data into by reading the TD value and splitting the 3D data using RSER2D along 13 dimension starting from folder 1000 (user editable). Now if the interleaved experiment is looped through F1 dimension in Topspin aqpars, one will need to split the 3D along 23 dimension. This can be done in the following script. Remember to place the macro in $PATH_TOPSPIN/exp/stan/nmr/au/src/user (The following script is called “splitrelax23”) int td, texpno=1000; GETCURDATA GETINT(“Enter the first target expno: “,texpno) FETCHPAR3S(“TD”,&td) i1=0; TIMES(td) RSER2D(23, i1+1,i1+texpno) i1 ++; END QUITMSG(“— splitrelax23 finished —“) These scripts will create individual folders with 2D data in them which can be processed using standard 2D NMRPipe scripts or using “xfb” command in Topspin.

Designing interleaved experiment in Bruker Topspin 3+

Interleaved NMR experiments are often used to collect relaxation dispersion, zz-exchange, CPMG relaxation and T1/T2/NOE relaxation etc. This is often done to minimize the effect of degradation of sample, precipitation and aggregation over time on individual experiments. These aforementioned experiments can be done as a bunch of 2D experiments queued one after another, but the intensities of a spectra of slightly unstable protein could vary over time causing addition artifacts. Approach Design a working version of the 2D experiment First we need a 2D version of the experiment one wants to run where we create a segment in the pulse sequence that is varied between the different experiments. In the case of relaxation dispersion experiment this variable is referring to the number of CPMG pulses that are applied over a small mixing time of ~40ms and in the case of zz-exchange experiment, this variable refers to the time in milliseconds that is used to mix between two states under equilibrium. Let us try to use a complex case where the loop counter is varied where a counter is used to determine the number of times a segment is repeated. We first need to pass the value of –DCPMG via ZGOPTNS if we want to activate CPMG sections of the pulse sequence which can be done using “# ifdef CPMG” command as described below. # ifdef CPMG 5  d26                      ; tau_cp    (p61*2 ph3):N15         ;CPMG specific section    d26                      ; tau_cp    lo to 5 times l2 # endif This will iterate the three lines of the code “l2” number of times which is also supplied by user via Topspin. Now testing this pulse sequence is all that is left to confirm the correct implementation of the delays and pulses. Once this is conformed we would proceed to the following step where we collect thse experiments as a pseudo-3D experiment. Pseudo-3D experiment In an interleaved experiment, the first scan is done for first loop counter value, subsequent scans for the following loop counters and at the end of loop it should start from the first value all over again until the number of scans are exhausted. We would later split these individual experiments and combine with corresponding loop counter using a Topspin macro (discussed in another post). We will base this experiment on the 2D experiment where “l2” is used as a loop counter to vary the number of times a certain section of the code is run. The F1 and F2 dimension of the 2D experiment is going to be converted to F1 and F3 in our pseudo-3D experiment and F2 dimension will be used in the “QF” mode to vary the number of points in the loop counter. This has certain advantages over using F1 dimension as a loop counter as the chemical shift variable names, their corresponding increments and MC loop names have to be changed throughout the pulse sequence. With the use of F2 for loop counter eliminates this issue and one can keep the exact same variable names as […]