Monday, April 2, 2018

A web configurable ThingSpeak logger, build on AVR ATmega328

ThingSpeak is an open source Internet of Things (IoT) application and API to store and retrieve data from things. It is an on-line database service allowing developers to connect sensor-derived data (e.g. energy and environment data from objects, devices & buildings) to the web and to build their own applications based on that data.

This embedded platform is a modular and configurable ThingSpeak data logger, built on an ATmega328 micro, usefull to send datapoints to your ThingSpeak feed.

This project is an update to the Xively logger presented here:
LogMeIn will retire this legacy version of Xively, that is Xively Personal, on January 15, 2018. For this reason I've made an update to my previous logger in order to update my products logger to ThinkgSpeak.

If you are going to use this logger, please read the linked post link about the Xively version. This version is almost identical to the Xively one, just a few things has been changed to meet the ThingSpeak RESTful API.

The POST method it is used to send data to Thinkgspeak.
Even this version has a network interface you can use to configure the Ip address and connection mode, and your ThingkSpeak API key and feed number.

If you are using the priouse version you have to update the main.c and main.h code files, and the _xivelygetdata methods of you sensors implementations, this function has been renamed to _thingspeakgetdata. Also, all the previous reference to xively has been renamed.

The hardware used is an ATmega328, running at 16Mhz, for this reason one can also use an Arduino board. The network board used is based on the EC28J60 IC.


  • read risk disclaimer
  • excuse my bad english

Sunday, March 4, 2018

An AVR ATmega R/C control signal reader - Method/02

The Radio Control (R/C or RC) is the method of controlling remote devices using radio frequencies.
Most of the time the RC signal uses RC servo signals.
Servo signal is a square PWM signal, usually with a period of 20ms and a duty time between 1ms and 2ms. More info on the wikipedia page here:

This library implements a method to read an RC signal and eventually map this to a 0..100 number.

There are a few methods of performing this task of course. Another alternative method i propose can be found here:

It's developed on an ATmega8 running at 16Mhz.
It makes use of the external interrupt PIN and a timer to count the duty period time.
It's customizable to fit the user preferences. Configuration can be found in rcin2.h header file.
This is slighly less accurate than the Method/01 proposed in the link above, but it uses less resources due to the slower timing needs.
Theory of operation: each time a rising edge interrupt it is raised the timer counter is stored, When the falling edge happens the difference between the actual timer counter and the stored one it is used to compute the duty time.
Input PIN is INT0.
The RC signal it is measured, eventually filtered using an exponential moving average filter, and then mapped to a speed value from 0 to 100.

  • read risk disclaimer
  • excuse my bad english

Monday, February 5, 2018

esp8266/Arduino 74HC4051 library

The 74HC4051 is a high-speed Si-gate CMOS device and is pin compatible with Low-power Schottky TTL (LSTTL).

The 74HC4051 IC can be used to expand the single ADC input port of the ESC8266, to 8 ports.
The ESP8266 comes with a 10bit ADC, 0 to 1V, the datasheet doesn't tell much more than this about the internal analog converter.

The output pin of the 74HC4051 is controller by 3 pins, by setting those pins high or low an analog input of the 74HC4051 is selected.
It can be driven by the same 3.3V that powers up the ESP8266.

This library was developed on Atom+PlatformIO, compiled esp8266/Arduino.


  • read risk disclaimer
  • excuse my bad english

Tuesday, January 2, 2018

esp8266/Arduino NTC library

A thermistor is a type of negative coefficient resistor whose resistance is dependent on temperature, more so than in standard resistors. The resistance of a NTC Negative Temperature Coefficient thermistor ( decreases as temperature rises. The Steinhart-Hart Thermistor Equation or the Beta Model Equation can be used to correlate the thermistor resistance to temperature to which the sensor is exposed.

The library implements the Steinhart-Hart Thermistor Equation or the Beta Model Equation to convert adc value read from analog input to temperature.
It output temperatures in Celsius or Fahrenheit.

The ESP8266 comes with a 10bit ADC, 0 to 1V, one can use the ESP8266 ADC for this library.
Suppose you are going to the internal ADC, and that NTC is going to be used between -20 and +100 degree Celsius. The NTC resistance by datasheet at -20 degree is 100k, and at 100 degree 100. To evaluate the pullup resistor you have to consider that the Voltage output at the ADC pin will be
Vout = Vpullup*(Rntc/Rntc+Rpullup)
We have to consider the max Vout, that comes from the max resistance given by the NTC
Voutmax = Vpullup*Rntcmax/(Rntcmax+Rpullup)
We have to chose a Rpullup such that Voutmax < 1V, so:
Rpullup = Vpullup*Rntcmax/Voutmax - Rntcmax
Subsitute with the sample NTC we are considering:
Rpullup = 3.3*100000/1 - 100000 = 230000.
A 220k resistor would do the job.

In the example i propose here I am using a ADS1015 12 bit analog to digital comparator, that is much more accurate than the internal ESP8266 ADC.
I am using the Adafruit ADS1X15 library for this IC, on top of that library I've build an helper to just convert the ADC raw value that comes from the ADS1x15 to a resistance or voltage value.

Once we've acquired the NTC resistance we can use the Steinhart-Hart Thermistor Equation or the Beta Model Equation to convert the resistance value to temperature.

A digital iir filter is implemented to remove unwanted reading errors.

This library was developed on Atom+PlatformIO, compiled esp8266/Arduino.


  • read risk disclaimer
  • excuse my bad english