Tag Archives: I2C

TSL2540 Ambient Light Sensor matches eye-response

TSL2540: Other Product Document (English)

ams (Graz, Austria) has posted details of the TSL2540, a very-high sensitivity light-to-digital converter. Evaluation kit is available:

The TSL2540 is a very-high sensitivity light-to-digital converter that approximates the human eye response to light intensity under varying lighting conditions and transforms this light intensity to a digital signal output capable through a 1.8V I²C interface. The ALS sensor features 2 output channels, a visible channel and an IR channel. The visible channel has a photodiode with a photopic Interferometric UV and IR blocking filter and the IR channel has a photodiode with an IR pass filter.

TSL2540 Ambient Light Sensor matches eye-response – [Link]

Real Time Clock On 20×4 I2C LCD Display with Arduino

Sometimes it may be necessary to use a display while making a hardware project, but the size and the type of the display may vary according to the application. In a previous project, we used a 0.96″ I2C OLED display, and in this project we will have an I2C 20×4 character display.

This tutorial will describe how to use 20 x 4 LCD display with Arduino to print a real-time clock and date.

Real Time Clock On 20×4 I2C LCD Display with Arduino – [Link]

DI2C -The Differential Version of I2C

In serial interface world, there are differential and non-differential protocols. The most famous one of differential interfaces is USB besides HDMI and others, while I2C is a non-differential one.
Joshua Vasquez from Hackaday decided to use DI2C (differential version of I2C) to communicate with a string of BNO055 sensor boards (a smart 9-DOF sensor with I2C interface).

If you’re not familiar with differential communication, the method behind it is straightforward; the line has two channels (positive and negative), where each line has the same signal but with an opposite voltage. The receiver then will calculate the difference between them. Mathematically:

Vb = -Va, So:
Vout = Va – Vb = Va – (-Va)

Image Source: Hackaday

Now, what if there was a noise?. The noise will affect almost identically on both signals with the same voltage level. As a result the receiver can omit the noise in the output.

Image Source: Hackaday

Back to I2C; Joshua used PCA9615 chip from NXP which is a bridge between the normal 2-wire I2C-bus and the 4-wire DI2C-bus.

PCA9615 Block Diagram.
PCA9615 Block Diagram. DSCLP and DSCLM are the clock plus/minus input/output respectively. While DSDAP and DSDAM are the datat plus/minus input/output.

As an use case; Joshua used DI2C to build an IMU Noodle for modeling a piece of foam twisting and turning in a 3D space simulator using data comes from a string of cards contain the BNO055 sensor and PCA9615 bridge.

PCA9615 was used in each Joshua’s card to bridge the normal I2C signals to DI2C ones. By bridging I2C to DI2C, PCA9615 makes the capability of using longer cables and I2C more rugged in noisy environments.

(a) PCA9615 Application Diagram (b) Ribbon-cable Connectors. (c) BNO055 with PCA9615 Module.

The PCB design files (KiCAD) and firmware can be downloaded from Joshua’s repository on Github. Moreover, Joshua mentioned important tips to setup DI2C in your next design. You can see these tips in his blog post on Hackaday.

IMU Noodle in Action

20×4 I2C Character LCD display with Arduino Uno

Our friends on educ8s.tv published a new video! Check it out.

Hello guys, I am Nick and welcome to educ8s.tv a channel that is all about DIY electronics projects with Arduino, Raspberry Pi, ESP8266 and other popular boards. Subscribe to the channel now if you don’t want to miss any future videos. In this video we are going learn how to use this inexpensive character LCD display with Arduino. After we learn how to use the display we are going to build something useful. A simple real time clock. Let’s start.

20×4 I2C Character LCD display with Arduino Uno [Link]

LTM9100 – Anyside™ High Voltage Isolated Switch Controller with I²C

The LTM9100 μModule is an all-in-one solution for controlling, protecting, and monitoring high voltage power supplies up to 1000VDC. A 5kVRMS galvanic isolation barrier separates the digital interface from the switch controller, driving an external N-channel MOSFET or IGBT switch. Isolated digital measurements of load current, bus voltage, and temperature are accessed via the I2C/SMBus interface, enabling power and energy monitoring of the high voltage bus. The LTM9100 saves design time, certification effort, and board area by wrapping all the needed functionality, including digital telemetry and isolated power, in a compact BGA package.

LTM9100 – Anyside™ High Voltage Isolated Switch Controller with I²C – [Link]

Basics of most common communication protocols

circuitbasics.com has published a series of tutorials on the most popular communication protocols, like UART, I2C, SPI etc. Check them on the links below.

Expand Your ESP8266 Analog Inputs With $10

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.

Allaboutee created the second version of their analog expander board. Simply it is a board that lets you add eight analog inputs to your ESP8266 via I2C, the first version had only four inputs.

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:

Expander pinout:

  • 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:

ESP8266 expander is available for $10 at tindie, it may be a bit expensive but with the cost of ESP8266, it is a very cheap alternative of the $100 Arduino Wifi shield.

“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

A LEGO-Compatible Digital Weather Billboard

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!

Through the IoL blog, Cory shares a collection of circuit projects, coding examples, and tutorials which use Arduino, Raspberry Pi, NodeJS, Node-RED, and LEGO.

cover

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:

  1. Raspberry Pi
  2. WeMos D1 mini
  3. OLED 128×64 I2C screen
  4. 2x LEDs
  5. 2x 220 ohm resistors
  6. Breadboard and wires
  7. 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.

WeMos D1 mini top and bottom faces
WeMos D1 mini top and bottom faces

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.

Adafruit Monochrome 1.3" 128x64 OLED graphic display
Adafruit Monochrome 1.3″ 128×64 OLED graphic display

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.

billboard-fritzing

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.

ESPEasy Firmware on Arduino IDE
ESPEasy Firmware on Arduino IDE

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.

Node-Red is pre-installed on the Raspbian Jessie image. Run the software and download this flow. It will accept an MQTT message on the topic “/sensors/iolcity/weather/#” and transmit it to the WeMos on the topic “/billboard/cmd”. Function nodes will format the message using JavaScript.

Node-RED Billboard MQTT Flow
Node-RED Billboard MQTT Flow

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.

Weather Station Based On ChipKIT

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.
It contains:

  • 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)

chipkit-uno32-obl-500-big-500x361

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.

p_20161109_153854-600

Hardware Setup:

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:

Connections between chipKIT Uno32, BME280 and Nokia 5110 LCD
Connections between chipKIT Uno32, BME280 and Nokia 5110 LCD
Software

You will need to install the following libraries prior to develop the firmware for this project.

Output

The program displays ambient temperature in Centigrade, humidity in %, and atmospheric pressure in hectopascal (hPa) units.

Weather station displaying temperature, humidity, and pressure shown in hPa unit.
Weather station displaying temperature, humidity, and pressure shown in hPa unit.

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.

Build Your Own I2C Sensor

Since Raspberry Pi doesn’t have a built-in ADC (Analog to Digital converter) to read the voltage off from most of sensors, the best solution is to add I2C ADC chips and modules to your project.

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.

ATtiny85 is a member of Atmel tinyAVR series which has 8-bit core and fewer features, fewer I/O pins, and less memory than other AVR series.

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.

425px-i2c-svg
Sample Inter-Integrated Circuit (I²C) schematic with one master (a microcontroller) and three slave nodes

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.

attiny_photoresistor_i2c
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.

Wire.requestFrom(0x13, 2);    // request 2 bytes from slave device #0x13

int i =0;
unsigned int readout = 0;

while (Wire.available()) { // slave may send less than requested
 byte c = Wire.read(); // receive a byte as character

 if (i == 0) {
  readout = c;
 } else {
  readout = readout << 8;
  readout = readout + c;
 }

 i++;
}

Serial.print(readout);

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 function is executed when there is a request to read sensor
* To get data, 2 reads of 8 bits are required
* First requests send 8 older bits of 16bit unsigned int
* Second request send 8 lower bytes
* Measurement is executed when request for first batch of data is requested
*/
void requestEvent() {
 TinyWireS.send(i2c_regs[reg_position]);

 reg_position++;
 if (reg_position >= reg_size) {
  reg_position = 0;
 }
}

/*
* Setup I2C
*/
TinyWireS.begin(I2C_SLAVE_ADDRESS);
TinyWireS.onRequest(requestEvent); //Set I2C read event handler

 

Bright by day, dark by night
Bright by day, dark by night

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.

For more details about this project you can check Github and the weather station website.