Monday, June 12, 2017

Extend your analog inputs




Intro

Is yours too small? You want to get more? No, that is no advertisement for a penis enlargement product. It's for a board to extend the numbers of analog inputs to your microcontroller.
It's quite rare that you run out of analog inputs, when using an Arduino Uno, Nano, Micro, etc. Even a ATTiny is already equipped with 4 analog inputs. BUT if you are so keen in using a ESP8266, like I am, you'll find your self in the position having only 1 (!)  analog in. This is where a digital to analog converter comes into play.


It's all about libraries

The name of the sensor (ADS1115) already can lead to the conclusion that the board is developed by Adafruit. And of course, if you'll open the library manager in the Arduino IDE and search for ADS1X15. There you have it all. Ready-To-Use library, good commented examples.

I2C on your NodeMcu board

The default pins for I2C on the NodeMcu board are pins D1 (SCL) and D2 (SDA). But the cool thing with the NodeMcu board is, you can define for yourself where the I2C has to be.

With the command:
Wire.begin();
You usually start the Wire-library, that is responsible for the I2C bus. But you can also add the pins for SDA and SCL as parameters:
Wire.begin(D2, D1); // Wire.begin([SDA-Pin],[SCL-Pin]);

There can be more than one

The ADC1115 has a fixed I2C address, like any other I2C device. Fixed? Not quite! It has up to five different I2C addresses. The default one, and four more addresses, that you can select by connecting the address pin (ADDR) with either SDA, SCL, GND or VDD.


Video


Wire up

Normal wiring


Wiring with two modules on I2C



Links

Adafruit Library
https://github.com/adafruit/Adafruit_ADS1X15

Amazon
ADS1115
NodeMcu

Friday, June 2, 2017

Keeping balance with a gyroscope




Intro

"I like to move it, move it! I like to move it, move it!"
If you want to measure movement, you probably will use one of these sensors. Why you want to measure movement anyway, you ask? Hey, who doesn't want to build a quadcopter? Or a self-balancing robot?
 There are 2 common senors, that will do the trick. The GY-61 (ADXL335) and the bigger brother the GY-291 (ADXL345).

The sensors

The GY-61 is the easier sensor to handle. It has VCC and GND and three analog outputs. One for each axis. You can read the sensor values with the analog inputs of an Arduino.
These are quite raw values. And even, when the sensor doesn't seem to move, the values does. So you have to program some method to smooth these values and probably a calibration routine, if you want to use it in a matter of a balanced project.
The GY-291 is a little different. It has an I2C bus. And I recommend to use the library, that is provided by Adafruit. If you're using the Arduino IDE, just search for ADXL345 in the Library Manager.



Video






Which sensor for which project?

Well the advantage of the GY-291 is, that you don't need to interpret the sensor values for yourself. The library does all the work for you. And it has a I2C bus. That means, you won't waste any pins on your controller. Because you can attach several devices to I2C, as long as they have different addresses. The smaller brother, the GY-61, doesn't need much code to operate. The sensor delivers it's values through 3 analog outputs. Well, at least it delivers something. You have to interpret the values for yourself. If you want to build something like a self balancing robot, I would recommend, that you build a small calibration routine. 
Both sensors costs about the same. 
For one of my next projects, where I want to use an ATtiny. Since the ram of this board is extremely limited and I just want to know, if the sensor is moving anyhow, I'll stick to the GY-61.

Links

Amazon