Learn To Write Code For 8051, Arduino, AVR, dsPIC, PIC, STM32 ARM Microcontroller, etc.
Coding Embedded Controller With C/C++.
Printed Circuit Board (PCB) Project For Electronics Hobbyists.
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.
Nodemcu V3 module #1
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.
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.
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:
Schematic diagram designed using Proteus
Finished Design:
PCB design preview
Previewing in 3D:
Preview of 3D design in Proteus
I put its copper layer side and legend side below.
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.
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.
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.
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.
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.
A Completed Assembling
Bottom side
These are some building block of the board:
A +12 V to +5 V DC regulated power supply
A soldered crystal clock and reset circuit
A 6-pin ICSP connector for downloading the program
A USB type-B connector
A DIP switch connected to PORTB
An 8-bit LED connected to PORTD
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.
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.
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.
// 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;
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.
A finished Assembling. SN74HC595N is soldered on-board. A 16x4 LCD stays at the top.
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:
Serial Clock
Serial Data
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.
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.
Arduino To SPI LCD connection diagram
I took the example program come with this LCD library.
The HelloWorld.ino Example Program
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.
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.
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:
Serial Clock
Serial Data
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.
Pins And Logic Diagram Of SN74HC595
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.
Fully Solder Board
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.
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.
A screen shot of PCB design
High Quality Print Copper Side.
An optional components side
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.