Tag Archives: I2C
ESP8266 is a very powerful module for building an IoT or WiFi-based project. But since it has only one analog input, you may need to use another microcontroller or circuit to connect multiple sensors and data sources with your ESP8266.
The expander is a 19x14mm board that is powered by a range of 2.7V to 3.6V, features 8 10-bit resolution analog inputs for sensors with an output voltage lower than 3.3V. Allaboutee developed some open source, easy to use libraries and examples:
- VDD – 2.7V to 3.6V (If using with ESP8266 you’ll have to use 3.3V for this pin).
- GND – Ground
- SCL – I2C clock (connect this to GPIO0 of the ESP8266)
- SDA – I2C data (connect this to GPIO2 of the ESP8266)
- A0 -> A7 – Analog inputs (0v to 3.3V)
You can not use two or more boards to have more than 8 analog inputs because the chip’s I2C is factory fixed. If you do not connect a pin to anything, it will be “floating”, that means it’s value is not defined so it can be anything.
This video shows the expander board in action:
“If you were to desire an Arduino based and thus easy to program, WiFi enabled microcontroller, then you could purchase an Arduino WiFi shield for $100+, OR you could instead get an esp8266 w/ breakout board for $6, A 3.3v voltage regulator for $1, the analog input expander $10 and an FTDI to USB 3.3v programmer $3.” – A review by Erol
Internet of LEGO “IoL” is an interactive LEGO city built and designed by Cory Guynn, a cloud computing and IoT enthusiast. This project combines computer and electronics engineering with our favorite childhood toy, LEGO!
A recently added project is a digital billboard that broadcasts the weather information from IoL local weather station. It uses a Raspberry Pi running Node-RED to collect weather data from the local station and display it on an OLED screen powered by an ESP8266.
The hardware materials needed for this project:
- Raspberry Pi
- WeMos D1 mini
- OLED 128×64 I2C screen
- 2x LEDs
- 2x 220 ohm resistors
- Breadboard and wires
- LEGO bricks!
And the required software:
WeMos D1 mini is a cheap mini wifi board based on ESP8266 and compatible with Arduino and NodeMCU. It has 11 digital I/O pins that support PWM, I2C, and interrupts, and has only one analog input with a microUSB connector. The WeMos D1 is available for only $4 and is supported by many shields.
The 128X64 OLED is about 1.3″ display, it is very readable due to its high contrast. This display is made of 128×64 individual white OLED pixels, each one is turned on or off by the controller chip. No backlight is required because the display makes its own light, which reduces the power required to run the OLED.
OLED’s driver chip, SSD1306 can communicate in two ways: I2C or SPI. The OLED itself require a 3.3V power supply and 3.3V logic levels for communication.
The display uses I2C connection at this project, so you will need to solder the two jumpers (SJ1/2) on the back of the OLED, then use the ‘Data’ pin as ‘I2C SDA’ pin and ‘CLK’ pin as ‘I2C SCL’. The WeMos D1, OLED, LEDs, and resistors are connected as shown in the figure.
To simplify configuring WeMos D1, a special firmware called “ESPEasy” has been used. It is a free and open-source web configurable software framework for IoT, which allows the device to be configured using the web browser instead of writing codes.
ESPEasy can be uploaded to the WeMos D1 using the Arduino IDE by installing the ESP8266 board support from Boards Manager, and then uploading the ESPEasy firmware as described in this tutorial.
MQTT is a lightweight machine-to-machine publish/subscription messaging protocol. It works like Twitter where each device will subscribe and/or publish to a topic, much like a #hashtag, and the payload will then contain the data being transmitted.
Mosquitto is a free open source broker that works perfectly on a Raspberry Pi. It is a MQTT server manages the MQTT message flow, and connects with all devices.
The last step is configuring the Raspberry Pi on the weather station for sending the information to the billboard. An easy way for that is using Node-Red, a visual tool for wiring together hardware devices, APIs and online services for IoT applications.
You can use it with your own weather station or any other sources of data, just change the MQTT input nodes to match your topics. To build a weather station check this IoL project and this ChipKIT-based station. Alternatively, you could get weather data using the Weather Underground service with the Node-RED node.
Further information and detailed description are available at the original project page.
ChipKIT Uno32 by Digilent is an easy-to-use platform for developing microcontroller-based applications. It uses chipKIT-core development environment and Arduino IDE for compatibility with existing code examples, tutorials and resources. Pin-compatible with many Arduino shields that can operate at 3.3V.
- PIC32MX320F128H processor
- 128K Flash, 16K RAM
- Up to 80 MHz operating speed
- 42 available I/O lines
- USB or externally powered
- USB cable required for programming (not included)
This kit is now discontinued and replaced by chipKIT uC32.
By following this tutorial you will be able to build a weather station based on chipKIT and using Bosch BME280 module, a fully integrated environmental unit that combines sensors for pressure, humidity, and temperature in a tiny 8-pin metal-lid LGA package of size 2.5 x 2.5 x 0.93 mm³. This module seems popular due to many features such as its support for standard I2C and SPI interfaces and availability of supporting open-source Arduino libraries.
R-B, the maker behind this project, uses BME280 to read barometric pressure, relative humidity, and temperature measurements then the readings will be sent via I2C bus and finally displayed on a Nokia 5110 LCD.
You will need these parts in order to build this project:
- ChipKIT Uno32
- BME 280
- Nokia 5110 LCD: It is a 48×84 pixels matrix LCD driven by the low-power PCD8544 controller chip. It is powered by 3.3V and includes on-chip generation of LCD supply and bias voltages, thus requiring minimum external components for its operation. The PCD8544 receives display data and commands from a microcontroller through a serial bus interface.
The complete hardware setup for this project is shown in the following figure:
You will need to install the following libraries prior to develop the firmware for this project.
- Adafruit unified sensor library
- Adafruit BME280 library
- Nokia 5110 LCD library for chipKIT: LCD5110_Basic
The program displays ambient temperature in Centigrade, humidity in %, and atmospheric pressure in hectopascal (hPa) units.
Full description of how to connect the modules together, how to set the I2C connection and more detailed information are available at the project page.
Just download the complete program, get the needed parts and you are ready to build your own weather station! You can check other tutorials by R-B here.
Paweł Spychalski faced this problem while building his own weather station that is based on Raspberry Pi. It collects various data and displays them on dedicated web page and Android app. Every few months he tries to add a new sensor to it. Last time it was a daylight sensor. He added this sensor to his system by using ATtiny85 and it was connected via I2C bus.
The Inter-integrated Circuit (I2C) Protocol is a protocol intended to allow multiple “slave” digital integrated circuits (“chips”) to communicate with one or more “master” chips. Like the Serial Peripheral Interface (SPI), it is only intended for short distance communications within a single device. Like Asynchronous Serial Interfaces (such as RS-232 or UARTs), it only requires two signal wires to exchange information.
I2C uses only two bidirectional open-drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V although systems with other voltages are permitted.
Most of developers use I2C to connect to sensors with the help of the Arduino “Wire” library or “i2c-tools” on the Pi, but it is rare to see someone that is actually building the I2C slave device. Paweł’s project uses TinyWireS library, a slave-mode SPI and I2C library for AVR ATtiny Arduino projects.
This diagram shows how to build analog to digital converter using ATtiny85 and connect it to any device (Raspberry Pi, Arduino) using I2C bus. Here photoresistor has been used, but any analog meter will be fine: temperature, potentiometer, moisture…
ATtiny85 directly connected to Raspberry Pi via I2C, photoresistor with 10kOhm pull down connected to ATtiny85 and signal LED.
For reading data you can use this code. ATtiny sends current measurement as two 8 bit value. First older bits, then younger 8 bits.
To do this project you need to use Arduino IDE 1.6.6., TinyWireS library,ATtiny45/85 board, plus an 1MHz internal oscillator.
Watchdog timer interrupts ATtiny every few minutes, measures voltage, filters it and stores in memory. Every time read operation is requested, last filtered ADC value (10 bits as 2 bytes). I2C support is provided by TinyWireS library that configures ATtiny USI (Universal Serial Interface) as I2C slave.
This cool weather station and its need of daylight sensor is only an example. The amazing thing is that you can now build new I2C sensors and introduce new modules to your projects easily following Paweł’s steps.
Paweł Spychalski build a photoresistor based daylight meter sensor connected via I2C bus using ATtiny85:
I love AVR ATtinyx5 series microcontrollers. They are cheap, easy to use, they can be programmed just like Arduinos and comparing to their size they offer great features. For example, they can be used as remote analog to digital converters connected to master device using I2C bus.
ATtiny85 Light Sensor – I2C slave device – [Link]
Raspberry PI RF Frequency Counter with Python Interface. The RF signal clocks a 32-bit counter (SN74LV8154) connected to a 16-bit IO expander (MCP23017) accessable to the Raspberry Pi (via I²C) to provide real-time frequency measurements from a python script.
Raspberry Pi RF frequency counter – [Link]
byteparadigm.com has a nice introductory article on I2C and SPI protocols:
Today, at the low end of the communication protocols, we find I²C (for ‘Inter-Integrated Circuit’, protocol) and SPI (for ‘Serial Peripheral Interface’). Both protocols are well-suited for communications between integrated circuits, for slow communication with on-board peripherals. At the roots of these two popular protocols we find two major companies – Philips for I²C and Motorola for SPI – and two different histories about why, when and how the protocols were created.
Introduction to I²C and SPI protocols – [Link]
The Tiny Lisp Computer is a self-contained computer programmed in Lisp. Some programming examples are included in the author’s website.
This article describes a self-contained computer with its own display and keyboard, based on an ATmega328, that you can program in Lisp. You can use it to run programs that interface to components such as LEDs and push-buttons via the I/O pins, read the analogue inputs, and operate external devices via the I2C and SPI interfaces. It has a small monochrome OLED display that gives 8 lines of 21 characters per line, and a miniature PS/2 keyboard
Tiny Lisp Computer using ATmega328 – [Link]
If your application requires a changing supply voltage, then this new IC is ideal for you. Intersil announced the ISL91128, a new buck-boost regulator. The new regulator has an I2C interface to select a broad set of features including output voltage range and slew rate. This eliminates the need of feedback resistors and allows the reuse of the same design for multiple output voltage needs.
The input voltage range is from 1.8V to 5.5V, and the output voltage range is from 1.9V to 5.5V with output current up to 2.2A. ISL91128 has 2.5MHz switching frequency. It is fully protected for short-circuit, over-temperature and undervoltage, according to the datasheet.
Intersil provides ISL91128IIN-EVZ, an evaluation board for ISL91128. ISL91128 is part of ISL911xx family of buck-boost/boost regulators.