Monday, March 15, 2021

A DIY ESP8266 I2C Testing Board

Introduction

ESP8266 is a system on a chip (SoC) specializing for Internet of Things (IoT) programming. It's very popular, and ease of programming. Most this chip is programmed using Arduino IDE with a lot of programming examples.

A DIY ESP8266 I2C Testing Board
Nodemcu V3 module #1

A DIY ESP8266 I2C Testing Board
Nodemcu V3 module #2

Nodemcu is single board computer containing esp8266 chip. It's ready to use with a factory programmed firmware. As shown in picture above, it has I/O connections, UART bridge for serial communication/program uploading, and on-board LED.

My Design

I'm interested in I2C devices communication with this module. I copped with I/O expanding while I was programming for my IoT project. I select MCP23017 for port expanding cause of it uses I2C requiring only two wires on a single bus. 

A DIY ESP8266 I2C Testing Board
My ready-to-use prototype

I added DS1307 real time clock IC, and an EEPROM chip. These three on board devices use I2C connected on a single two-wire bus. Hence other remaining I/O of esp8266 can be use for other hardware's interfacing - sensor, LCD, etc.

A DIY ESP8266 I2C Testing Board
Copper soldering side

I made this board by hands using dry film method at copper side. At components side I use toner transfer method, sticking laser printer toner text with PCB panel.

I design this PCB using Proteus as I am experienced with this software a decade now.

Schematic:

A DIY ESP8266 I2C Testing Board
Schematic diagram designed using Proteus
Finished Design:

A DIY ESP8266 I2C Testing Board
PCB design preview
Previewing in 3D:

A DIY ESP8266 I2C Testing Board
Preview of 3D design in Proteus


I put its copper layer side and legend side below.

A DIY ESP8266 I2C Testing Board
Copper layer - Normal
A DIY ESP8266 I2C Testing Board
Component side - Miror

Click here to download this PCB design package.

Sunday, March 14, 2021

ATMega32 interfaces to keypad and display

Introduction

A keypad is commonly found on telephone, ATM machine, fax machine, etc. It's arranged in matrix form, 3x4, 4x4, etc. The advantage of matrix arrangement of this digital input is saving the number of controller digital I/O. As an instance, a 4x4 keypad matrix requires only 8 pins of micro-controller, but it yields 16 difference keys.

ATMega32 interfaces to keypad and display
Simulation of this example program

Programming

Using 8-bit of a micro-controller's digital I/O port, this single port is divided into two nibbles. Lower nibble (column) is an output while higher nibble (row) is an input.

We use C loop of four repetition to generate key scanning routine. Whenever any key is pressed, the program determines which column and row are logic low that lead to key founding.

ATMega32 interfaces to keypad and display
Circuit diagram

As show in picture above, Port C connects to a 4x4 keypad matrix. These keypad gives key values of 0 to 9, and A to F, which is a hexadecimal representation.

Port D connects to a single seven segments display showing pressed key value. ATMega32 here uses its internal 8MHz oscillator.

I divide this program into C main file, and its keypad library I wrote for my own use.

C main file:

/*
 * _8_Keypad_C_SSD.c
 *
 * Created: 4/24/2018 8:51:03 PM
 *  Author: admin
 */ 


#include <avr/io.h>

#define F_CPU 8000000UL
#include <util/delay.h>

#include "keypad4x4.h"

int main(void)
{
DDRD=0xFF;
PORTD=0x00;
keyInit();
    while(1)
    {
        //TODO:: Please write your application code 
PORTD=scan();
_delay_us(100);
    }
}

C library header file:

/*
 * keypad4x4.h
 *
 * Created: 4/24/2018 8:52:11 PM
 *  Author: admin
 */ 


#ifndef KEYPAD4X4_H_
#define KEYPAD4X4_H_

#endif /* KEYPAD4X4_H_ */

extern unsigned char scan();
extern void keyInit();

C library file:

/*
 * keypad4x4.c
 *
 * Created: 4/24/2018 8:55:01 PM
 *  Author: admin
 */ 

#include <avr/io.h>
#include "keypad4x4.h"

#define KEY_DATA PORTC
#define KEY_DIR DDRC
#define KEY_PIN PINC

unsigned char keypad[4][4]={{0x07,0x7F,0x6F,0x71},
                            {0x66,0x6D,0x7D,0x79},
                            {0x06,0x5B,0x4F,0x5E},
                            {0x77,0x3F,0x7C,0x39}};

unsigned char output[4]={0xFE,0xFD,0xFB,0xF7};
unsigned char input[4]={0xEF,0xDF,0xBF,0x7F};
unsigned char key_value;

void keyInit(){
KEY_DATA=0xFF;
KEY_DIR=0x0F;
}

unsigned char scan(){
unsigned char i,j;
for (i=0;i<4;i++)
{
KEY_DATA=output[i];
for (j=0;j<4;j++)
{
KEY_DIR=input[j];
if ((KEY_PIN&0xF0)!=0xF0)
{
while((KEY_PIN&0xF0)!=0xF0);
key_value=keypad[j][i];
break;
}
}
}
return key_value;
}

If you want a standard PCB for ATMega32 micro-controller, you can order my AVR Microcontroller project from PCBWay with a reasonable price. Click here to get a free $5 credit for new account.

Interfacing ATMega32 to 74HC595 shift register
ATMega16 ATMega32 Experiment Board PCB from PCBWay
 

Click here to download this example.


See Also,


Wednesday, March 3, 2021

Making a PIC18F4550 Learning Board

Overview

PIC18F4550 is an 8-bit micro-controller from Microchip. In the PIC18 series, it has a built-in USB communication module inside. In prototyping we usually built the circuit on a bread board with some jumper wire. It usually cause damage to the device when we wrongly connect the circuit.

making a PIC18F4550 Learning Board
PIC18F4550 in DIP package I posses. 

Using a per-soldered board most of prototyping is safer and more reliable. Some ready made learning board could be found on E bay or  Amazon below 10 US Dollars.

PCB Project Design And Make

However, we can build our own learning board at home using a dozen of existing components. I made a simple learning board by myself at free time. The design fits any 40-pin 8-bit PIC device. But I tend to use PIC18F4550 with a USB type-B connector on board.
 
making a PIC18F4550 Learning Board
A Completed Assembling
 

making a PIC18F4550 Learning Board
Bottom side

These are some building block of the board:
  1. A +12 V to +5 V DC regulated power supply
  2. A soldered crystal clock and reset circuit
  3. A 6-pin ICSP connector for downloading the program
  4. A USB type-B connector
  5. A DIP switch connected to PORTB
  6. An 8-bit LED connected to PORTD
  7. Six POTs  connected to analog input pins RA0 to RA5
I have already test the functionalities of this board and it's fully worked.

The overall schematic and PCB design are made using Proteus 8.

making a PIC18F4550 Learning Board
Schematic Diagram


making a PIC18F4550 Learning Board
Copper Side

making a PIC18F4550 Learning Board
Components Side
 

PIC18F4550 Tutorials In CCS PICC

Reading the temperature from DS18B20 one-wire digital thermometer

Overview Of DS18B20

DS18B20 is a digital interface temperature sensor from Maxim Integrated. It has only one wire digital data input output, with two additional supply voltage pins. The temperature conversion from this device ranges from -55 degree Celsius to +125 degree Celsius. 
 
Digital temperature resolution is select-able between 9 to 12-bit. Within these 12-bit digital data, it consists of signed value, decimal temperature value and a 4-bit fraction numbers.

Reading the temperature from DS18B20 one-wire digital thermometer
A temperature reading from DS18B20 strobe-type.

 
Using only one wire digital data line, we can use multiple devices on this single wire. Each device is identified by its serial number and family code.

The conventional package and pin diagram of DS18B20

Within three pins of this device, the data DQ pin is open-drain. Hence it needed to pull up high via a resistor about 4.7 kOhm of resistance.

Typical connection to MCU

In some case, it doesn't require VDD.

Arduino Interfaces To DS18B20 With OneWire Library

Using the OneWire library developed by an author on Github, reading the device ID and temperature from this device family save a lot of time.
 
Installed library for OneWire
 
This library allow us to search for ROM. ROM identifies the devices connect on one wire bus. So we can use as much as one wire devices on a single line.

There are many function that I don't list them here. The example programs come this device could explain a lot about the overall processes.

In this example, I modified the device search and temperature reading to display their information on a SPI character LCD I made.

Reading the temperature from DS18B20 one-wire digital thermometer
Schematic Diagram For This Example

Arduino code lists below.

#include <OneWire.h>
#include <ShiftedLCD.h>
#include <SPI.h>

//OneWire Object Connect To Pin 2
OneWire  ds(2);

//Select pin 8 for Enable pin
LiquidCrystal lcd(8);

String dsString="";

void setup(void) {
  Serial.begin(9600);

  lcd.begin(16,4);
  lcd.clear();
 
}

void loop(void) {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
 
  if ( !ds.search(addr)) {
    ds.reset_search();
    delay(250);
    return;
  }
 
  if (OneWire::crc8(addr, 7) != addr[7]) {
      return;
  }
 
  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
     
      type_s = 1;
      dsString="DS18S20";
      break;
    case 0x28:
     
      dsString="DS18B20";
      type_s = 0;
      break;
    case 0x22:
     
      dsString="DS1820";
      type_s = 0;
      break;
    default:
     
      dsString="N/A";
      return;
  }

  lcd.setCursor(0,0);
  lcd.print("Sensor: "+dsString);
 
  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
 
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
 
  present = ds.reset();
  ds.select(addr);   
  ds.write(0xBE);         // Read Scratchpad

 
 
 

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
 
  lcd.setCursor(0,1);
  lcd.print("Temperature:");
  lcd.setCursor(-4,2);
  //lcd.print(String(celsius)+char(223)+"C" +" " + String(fahrenheit)+char(223)+"C");
  lcd.print(String(celsius)+char(223)+"C");
  lcd.setCursor(-4,3);
  lcd.print(String(fahrenheit)+char(223)+"F");
  delay(1000);
}


Arduino sketch could download here.

Making An SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR

Overview

A character LCD based on HD44780 is popular due to ease of programming. However, its interface is 8-bit parallel mode. Software technique could reduces the 8-bit interface to 4-bit mode, but it still require additional control pins.

 

Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
A finished Assembling. SN74HC595N is soldered on-board. A 16x4 LCD stays at the top.

Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
Soldering side

With SN74HC595N, the interface from the MCU to this LCD could reduce in pins requirement. SN74HC595 acts as an interface converter from SPI to parallel output. Using this device, the MCU uses only three pins:

  1. Serial Clock
  2. Serial Data
  3. Enable Pin

And it needs two extra supply pins.

Because of its low cost, I decided to make my own LCD adapter board for this chip. I possess a lot of shift register and character LCD module. I design my own schematic and PCB. The PCB is printed in my personal workshop.

Proteus 8 is very easy to design schematic and PCB due to its simplicity and light weight in components database and design rules.

 

Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
Schematic Diagram

Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
A photo of finished PCB design
      

Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
Copper side
Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
Components side
Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
A software rendered 3D view

Full design work could download here.

Arduino Interfacing And Programming

Library for this kind of LCD is widely available online. There are many authors make this libraries. I use a library develops by an author shared on Github.

For connection between Arduino Uno to this LCD module, wire as follow.

Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
Arduino To SPI LCD connection diagram

I took the example program come with this LCD library.

Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
The HelloWorld.ino Example Program

Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
The HelloWorld.ino tested on physical hardware

There are some basic function in this library.

  • LiquidCrystal lcd(x) - Where x is any pin (slave select). This object must declare first prior to LCD function usage.
  • lcd.begin(cols,rows) - Set number of rows and column for character LCD, typically it is 16 columns and 2 rows.
  • lcd.setCursor(x,y)  - Set the cursor before writing to LCD. Both x and y start from 0.
  • lcd.print() - Print any string or number value to LCD
  • lcd.clear() - Clear LCD screen

There are many functions left as referred in library function on Github. 

Now I try to test my own program for this LCD using existing library.

Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
Another Test Program

Arduino file could download here.

Making A SPI 16x4 Character LCD With SN74HC595N For Arduino PIC And AVR
Physical hardware test

We can also control this SPI LCD module using the ATMega32. Another simple method is using the SN74HC164 serial to parallel shift register IC. It need three pins of microcontroller.

Making a 74HC595 LED driver for Arduino PIC and AVR

LEDs Driver Making

As referred in the previous post, I made a single seven segments board based on SN74HC595N.

Here, I make a similar one, but the 74HC595 at this time drive 8 LEDs. It's just a simple example of using 74HC595 with Arduino. 

Making a 74HC595 LED driver for Arduino PIC and AVR
A sample of running program
 

I use Proteus 8 to design the schematic and PCB.

Making a 74HC595 LED driver for Arduino PIC and AVR
Schematic Diagram
 

I export the PCB pattern including copper track and legend side.

Making a 74HC595 LED driver for Arduino PIC and AVR
Copper Side
 

Making a 74HC595 LED driver for Arduino PIC and AVR
Top Silk
 

Making a 74HC595 LED driver for Arduino PIC and AVR
A 3D View
 

Making a 74HC595 LED driver for Arduino PIC and AVR
A completed Soldering Board

Making a 74HC595 LED driver for Arduino PIC and AVR
 

The Proteus design file could be downloaded here

Arduino Programming And Interfacing

I use the same shiftOut() function to transmit the data the registers. With and additional random() function to create a random numbers up to 255, and displaying it on LEDs.

The syntax of random() function is:

random(max)
random(min, max)

Where,

  • min - is the lower bound value
  • max - is the upper bound value
This function return a created random number as set. 
Arduino source code lists below.
 
Making a 74HC595 LED driver for Arduino PIC and AVR
Arduino sketch
 

Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR

Overview

Using 74HC595 shift registers, we can drive any display such as 7-segment or a dot matrix. It saves the controller pins with only three control signals requirements. These control signals are:

  1. Serial Clock
  2. Serial Data
  3. Enable pin

Two extra power supply pins are VCC and GND. Using these three pins we can drive a large amount of shift register as we need, for example 10 8-bit shift register.

A sample images of SN74HC595N from online store.
 

Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR
Pins And Logic Diagram Of SN74HC595
 

Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR
Timing Diagram
 

I make a single seven segments board driven by a single 74HC595 shift registers. I remove this single seven segments from an HP Print/Scan/Copy machine.

 
Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR
Fully Solder Board

 

Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR
Copper Side After I Soldered.

This board is made using a simple toner-transfer method. I use my own HP laser printer with my hot plate iron at home.

Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR
Schematic Diagram. The SSD is common anode type.

The SSD I used here is common anode type. I added three 1N4148 switching diode to reduce the voltage. Since each 1N4148 has a voltage drop of ~1V, thus three of this could make a voltage drop of ~3V. The SSD needs only ~2V of nominal working voltage.

Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR
A screen shot of PCB design
Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR
High Quality Print Copper Side.
Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR
An optional components side

Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR
I took a 3D view of this PCB.
 

Design file could be downloaded here. The file Proteus 8 format. Please use the latest version to open.

Arduino Test Program

Arduino is popular due to ease of programming. I test this board with Arduino Uno I possess. I use shiftOut() function to interface to 74HC595. This function is considered as a software SPI. We can declare any pin on Arduino to shift out clock and data.
 
The syntax of shiftOut() is:
 
shiftOut(dataPin, clockPin, bitOrder, value)
 
Where,
  • dataPin - Serial data output synchronizes with clock
  • clockPin - Serial clock output 
  • bitOrder - Decide which bit order to transfer first. It could be MSBFIRST or LSBFIRST
  • value - An 8-bit data to transfer   
 In this programming interface I use board to display value between 0 and F, since the hexa decimal has 16 values.
 
The sketch is shown below.
 
Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR
Arduino Test Program
 
Making A Single 74HC595 Seven Segments Driver For Arduino PIC And AVR
Counting reaches 0x0A is hex.
 
Arduino test program could be download here
 
 

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (54) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (46) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (66) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (2) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (30) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)