HackerBox 0081: Contact
by HackerBoxes in Circuits > Microcontrollers
4184 Views, 10 Favorites, 0 Comments
HackerBox 0081: Contact
Welcome to HackerBox 0081. Let's Make Contact. Assemble two experimental kits for exploring multiple communication modes. Communicate Morse coded messages or continuous-wave (CW) mode over an optical laser link. Configure the Arduino IDE for embedded development on Logic Green LGT8F328P microcontrollers. Modulate text messages directly from a keyboard or serial terminal onto an optical laser communication link. Experiment with data rates and cable lengths for RS-485 serial communication links. Configure Sonoff Mini Smart Switches to explore home automation technologies.
HackerBoxes are the original monthly subscription for electronics, computer technology, and hacker culture. Each HackerBox is a discovery box, which means all members await and enjoy a new surprise each month. Tech, toys, knowledge, and fun. It's like having a hacker convention, your birthday, and the first day of school - every month - right in your mailbox.
There is a wealth of information for current and prospective members in the HackerBoxes FAQ. Almost all of the non-technical support emails that we receive are already answered there, so we'd really appreciate it if you can take a few minutes to read the FAQ.
Supplies
This Instructable contains information for getting started with HackerBox 0081. The full box contents are listed on the product page for HackerBox 0081 where the box is also available for purchase while supplies last. If you would like to automatically receive a HackerBox like this right in your mailbox each month with a $15 discount, you can subscribe at HackerBoxes.com and join the party!
A soldering iron, solder, and basic soldering tools are generally needed to work on the monthly HackerBox. A computer for running software tools is also required. Have a look at the HackerBox Workshops for basic tools and a wide array of introductory activities and experiments.
The most import thing you will need is a sense of adventure, hacker spirit, patience, and curiosity. Building and experimenting with electronics, while very rewarding, can be tricky, challenging, and even frustrating at times. The goal is progress, not perfection. When you persist and enjoy the adventure, a great deal of satisfaction can be derived from this hobby. Take each step slowly, mind the details, and don't be afraid to ask for help.
Logic Green LGT8F328P MCU Module
The Logic Green LGT8F328P microcontroller is compatible (same instructions, registers, and pins) with the ATMega328P microcontroller. Of course, the ATMega328P is the chip we all know from the Arduino UNO and Arduino NANO boards.
The LGT8F328P has a few interesting improvements over the ATMega328P:
The LGT8F328P can run at 32MHz instead of the ATMega328P's 16MHz.
The LGT8F328P includes a Digital to Analog Converter (DAC) on one pin. The DAC can generate a true analog output as opposed to the noisier Pulse Width Modulated (PWM) output of the ATMega328P.
The LGT8F328P has an increased resolution for its Analog to Digital Converter (ADC) up to 12bits from 10 bits.
INSTALL THE ARDUINO IDE SOFTWARE
If you do not have the Arduino IDE installed on your PC, download it here.
BEFORE SOLDERING - CONNECT THE MODULE TO YOUR PC
A red power LED will light up, and a blue user LED will blink slowly.
RUN THE ARDUINO IDE
Select the following setup parameters:
- Tools > Board > Arduino AVR Boards > Arduino Nano
- Tools > Processor > ATmega328P (Old Bootloader)
- Tools > Port > [the one that appears when the board is plugged in]
If a new USB port does not show up for the module, you may need to install a driver for the USB chip. Most operating systems have a built-in CH340 driver, which will will work fine with the CH9340C chip on the LGT8F328P module. However, should you need to install a driver, here is a useful tutorial.
FIRST SKETCH
Open Files > Examples > Basics > Blink
Look over this code. It is the program that came on the module from the factory: slow blinking blue user LED.
Let's modify the code the make the LED blink ten times faster:
Change the two delay(1000) calls to delay (100).
Hit the arrow icon to compile and upload the modified code. Blinking faster now?
MOSTLY GOOD, BUT NOT PERFECT
Using the Arduino Nano settings in the IDE should have worked fine for that simple example, but they will not work for everything... For example, open:
Files > Examples > Basics > AnalogReadSerial
Compile and upload the file. Open Tools > Serial Monitor and set the baud rate to 9600.
The output will be garbage. This is because the Logic Green LGT8F328P MCU has a different crystal and clock circuit, which impacts the serial UART's clock generator. Let's fix this...
ADD A BOARD MANAGEMENT PACKAGE
Follow the directions here to add the specified URL under File > Preferences > Additional Board Managers.
Then use Tools > Board > Boards Manager to search for and select LGT8FX.
Now we can configure these options:
- Tools > Board > LGT8F328
- Tools > Clock Source > Internal
- Tools > Clock > 32MHz
- Tools > Variant > 382P-LQFP32(e.g. MiniEVB nano-style and WAVGAT)
VERIFY THE "FIX"
Again compile and upload the AnalogReadSerial sketch.
The output in the Serial Monitor (set to 9600 baud) should now be a nice looking list of numbers (mostly three digit values).
Electronic Kit: LET'S MAKE CONTACT
HackerBox 0081 has everything you need to assemble two LET'S MAKE CONTACT Kits.
There are two kits because they will each need one another to "make contact" with. Obviously.
Each kit includes the following items:
- Custom LET'S MAKE CONTACT Printed Circuit Board
- LGT8F328P MCU Module
- OLED Display Module 0.96 inch
- Laser Transmitter
- ISO203 Laser Receiver
- MAX485 DIP8 Chip
- DIP8 Chip Socket
- Common Cathode RGB LED 10mm
- Piezo Buzzer
- Two 100nF Ceramic Capacitors
- 10uF Electrolytic Capacitor
- Tactile Button with Black Cap
- Screw Terminal with 2-Pins
- One 120R Resistor
- Three 330R Resistors
- Six 10K Resistors
- Two 20K Resistors
- Four Adhesive Rubber Feet
- Bare Copper Wire ~75mm
- Mini-DIN PS/2 Keyboard Socket
Kit Assembly: LET'S MAKE CONTACT - Part 1
As always, it is helpful to solder components in order from the flattest/lowest to the tallest. The order specified here may be helpful...
Twelve Resistors
Identify each of four resistor values and place them in the locations shown below. Resistors are not polarized and can be oriented in either direction.
- One 120R Resistor
- Brown, Red, Brown
- Location: R4
- Three 330R Resistors
- Orange, Orange, Brown
- Locations: R1, R2, R3
- Six 10K Resistors
- Brown, Black, Orange
- Locations: R7-R12
- Two 20K Resistors
- Red, Black, Orange
- Locations: R5, R6
Two 100nF Ceramic Capacitors
These are mounted in locations marked C2 and C3 on the PCB.
The two small yellow/orange capacitors are marked with "104".
That represents ONE, ZERO, and then four more ZEROS (1 0 [0000] pF).
Where 100,000 pF = 100 nF = 0.1 uF.
Ceramic capacitors are not polarized and can be oriented in either direction.
DIP8 Chip Socket
Orient the eight pin socket so that the semi-circular notch on one end matches the same marking on the PCB silkscreen. Solder the socket while it is still empty. The MAX485 Chip will be installed in the socket, again matching up the same semi-circular notch. The chip can be insert just after the socket is soldered, or better yet, wait until all the soldering is complete and insert the chip at the end.
OLED Display Module
It is definitely not necessary, but the plastic insulator on the pins can be slid off to allow the display module to sit totally flush against the PCB.
LGT8F328P MCU Module
Orient the MCU module such that the USB-C connector extends over the edge of the PCB. Use the two long strips of header pins that came with the MCU module to connect it to the the PCB. The headers will need to be soldered to the MCU module on the top and also to the PCB on the bottom.
ISO203 Laser Receiver
Orient the laser receiver such that the round lens on the front faces out from the edge of the PCB (away from the MCU module).
Buzzer
Match the pin nearest the "+" marking on the buzzer to the hole nearest the "+" marking on the PCB.
Kit Assembly: LET'S MAKE CONTACT - Part 2
Just keep soldering... just keep soldering... just keep soldering...
10uF Electrolytic Capacitor
The black cylinder is mounted in the location marked C1 on the PCB.
Electrolytic capacitors are polarized and must be inserted in the correct orientation. The PCB has a white side (this is negative) and a black side with a very tiny "+" marking (this is positive). The capacitor has a white stripe marked "-" and aligned with the shorter lead (this is negative) and a the other lead is longer (this is positive).
Tactile Push Button
Solder the push button into place at location SW1. After soldering, the round, black, plastic cap may be snapped onto the push button.
Screw Terminal with 2-Pins
Mount the screw terminal at location J4. Orient the terminal such that the square wire opens extend towards the edge of the PCB. Unshielded Twisted Pair (UTP) wire can be connected to this terminal for RS-485 communications.
Common Cathode RGB LED
The RGB LED is mounted at location D1. The longest of the four wire leads is the common cathode (negative or ground). Orient the LED such that this longest wire is in the second hole from the MCU module.
MiniDIN PS/2 Keyboard Socket
Put it where it goes. Mind not to bend the smaller pins.
Laser Module
There is a piece of 20 gauge bare copper wire in the parts bag. It is approximately 150mm long. Cut it about in half so that one piece of bare wire about 75mm long can be used for each one of the two kits.
Gently form one of the wire halves into the shape as shown above. Capture the laser module inside the circle with the copper wire resting in the groove around the outside of the laser.
The bare copper wire holds the laser and allows the laser to be aimed by gently bending the wire as needed. The wire is able to hold the laser by the groove. While the wire can be bonded to the laser, it isn't necessary or recommended. Bonding with solder is a bad idea since it is very easy to damage the laser assembly with heat. Epoxy might be the safest bet, but again it is not necessary.
Four holes in the PCB are marked "LASER1". The hole labeled "+" is for the red wire of the laser. The hole marked "-" is for the blue wire. The remaining two holes (the outer two) are for soldering in the two ends of the bare copper wire. These two solder joints will hold the bare wire mount quite sturdily in place. The wire can be gently bent or twisted to aim the laser into alignment with the ISO203 receiver on the other board during communication experiments.
Four Rubber Feet
Stick these to the bottom of the PCB.
LET'S MAKE CONTACT - Firmware
Download the code
Grab the Contact.ino sketch attached here.
Install two libraries
Note the comment at the top of the sketch file about how to find the correct Arduino Libraries using the "Tools > Manage Libraries" menu in the Arduino IDE. These are the two we will need:
- SSD1306 (OLED) - use the one from Alexey Dynda
- PS2 Keyboard - use the one from Paul Stoffregen
Compile and upload the sketch to both boards
The firmware enables six different modes of operation:
- Transmit (TX) Morse on Laser
- Receive (RX) Morse on Laser
- Transmit (TX) Text on Laser
- Receive (RX) Text on Laser
- Transmit (TX) Text on RS-485
- Receive (RX) Text on RS-485
Use the pushbutton to select a transmit mode on one board and then select the corresponding receive mode on the other board.
The Morse Code transmit mode uses the push bottom to key dots and dashes on the laser. The receiver will illuminate its LED and sound a tone when the laser receiver is activated by the laser.
Both text transmission modes can accept text input from both the serial port (serial monitor) and from a PS/2 keyboard. The text will be displayed to the local OLED while also being transmitted to the other board.
Both text receiver modes will output the received text to both the serial port (serial monitor) and the OLED display.
A note about the PS/2 keyboard input
The little green passive USB to PS/2 adapters that we all have lying around do not automatically work with all USB keyboards. Some keyboards are designed to switch into PS/2 mode, and should work fine with the green passive adapters. The keyboard that the adapter originally came with, for example. However, more and more newer USB keyboards do not support PS/2 interfacing and will only work with USB. These keyboards will not support PS/2 mode even when used with the green passive adapter.
Downloads
Communicating With Light
The most basic of optical transmission, be it fiber optic or free-space, rapidly switches the light source (laser in this case) on and off. This is a modulation technique called on–off keying (OOK).
In the example code, each byte is transmitted between two start bits (a zero followed by a one) and two stop bits (also a zero followed by a one). This is called the data framing. Each byte of eight bits is framed between the start bits and the stop bits.
RS-485
RS-485 is a standard defining the electrical characteristics of drivers and receivers for use in serial communications systems. RS-485 supports inexpensive local networks and multidrop communications links using differential signaling over twisted pair cables. RS-485 can be used with data rates up to 10 Mbit/s or, at lower speeds, distances up to 4,000 feet. As a rule of thumb, the data rate in bit/s multiplied by the length in meters should not exceed 100,000,000. Thus a 50 meter cable should not be expected to carry data a rate higher than 2 Mbit/s. Multiple receivers may be connected to an RS-485 multidrop bus. RS-485 is useful in industrial control systems and similar applications. (Wikipedia)
The RS-485 chip on the LET'S MAKE CONTACT boards is the MAX485 (datasheet).
Challenges
Consider trying some of these...
- Add a Morse code generator to the transmit side
- Add a Morse decoder to the receive side
- Find the highest CW (Morse) word rate you can decode by ear
- For each laser mode, find the maximum transmission distance
- Which laser mode has the longest range
- Test if the laser link can be "bent" using a mirror
- Find a max length of UTP cable for RS-485 transmission
- Explore how data rate impacts that max wire length
- Upgrade one of the communication modes to full-duplex
- Set up a closed-circuit chat network over RS-485
Sonoff Mini R2 Smart Switch
The Sonoff Mini R2 Smart Switch is so compact, it can be integrated into an electrical switch box.
OF COURSE: Smart switch devices may be connected to home mains power. Mains power can be dangerous. You should understand the implications of connecting devices to mains power. Do not ever work on a device while it is connected to the mains power source. Do not attempt to adjust, modify, or program a device while it is connected to a mains power source. If you lack the experience or comfort to safely work with mains power, please have someone with the proper expertise join in to help you out. SAFETY FIRST!
For a general overview of smart switch technology, check out the Box Guide from HackerBox 0054: Smart Home
Specs for the Sonoff Mini R2:
- Voltage: 100-240 VAC 50/60Hz
- Wi-Fi IEEE 802.11b/g/n 2.4GHz
- Security: WPA/WPA2
- Encryption: WEP/TKIP/AES
Flashing Tasmota (Also see general info about Tasmota)
3 - 2 - 1 - Contact
We hope you are enjoying this month's HackerBox adventure into electronics, computer technology, and hacker culture. Reach out and share your success in the comments below or other social media. Also, remember that you can email support@hackerboxes.com anytime if you have a question or need some help.
What's Next? Join the party and live the HackLife. Get a cool box of hackable gear delivered right to your mailbox each month and enjoy a generous member discount. Surf over to HackerBoxes.com right now and sign up for your monthly subscription to HackerBox or the new HackBox Byte Size.