Arduino: Difference between revisions
From charlesreid1
| Line 75: | Line 75: | ||
===Useful Hardware=== | ===Useful Hardware=== | ||
You will need some hardware to talk to the wifi chip to program it. Specifically, you need a converter to turn 5V logic signals into 3.3V logic signals. You also need a separate power source for the wireless chip to ensure it can draw the full 300 mA it requires. | |||
USB-to-Serial TTL converter: | |||
* good for debugging via serial, doing one-off tasks via a computer | |||
* advantages: separate power supply | |||
* disadvantages: you can only interface with the wifi chip via the computer | |||
USB to serial TTL chip: | |||
* this is necessary for you to interface with the wifi chip with any ol serial device | |||
* advantages: allows you to use a Raspberry Pi or an Arduino | |||
* disadvantages: may require soldering, so need to find the right board | |||
bi-directional logic converter: 3.3V to 5V (very cheap): https://www.sparkfun.com/products/12009 | bi-directional logic converter: 3.3V to 5V (very cheap): https://www.sparkfun.com/products/12009 | ||
Revision as of 02:41, 14 June 2016
Basic Circuits
Hello World
A simple circuit showcasing "Hello World" on the Arduino.
Blink
Blink Arduino Micro - covers a simple blink program, then improves it by incorporating a morse code library.
Blink Arduino Leonardo - covers a simple blink program for the Arduino Leonardo
Morse Code on Arduino
Sending morse code on an Arduino is a little more tricky than you might think - at least when it comes to anything beyond the basics. For example, how do you take measurements from a sensor while keying morse code? What about timing - how long do you wait between letters? words? dots? dashes?
In any case, I've looked into a couple of different morse code libraries for the Arduino, with a rundown of how to install and use each of them.
Arduinomorse
A guide to installing the Arduinomorse library from GitHub user Mark Fickett, which allows you to send morse code with the Arduino by including a header:
The Arduinomorse library has a fire-and-forget philosophy. You tell the keyer to transmit something, at a certain speed, and then you go off and do other things, like talk to your sensors. This can be good - if you're trying to do lots of things with a single sensor and you just want to send some morse code. But this can be bad if you want greater control over the speed of your morse code while it is transmitting.
In one of the projects below, I wanted to use a potentiometer to control the speed of a morse code keyer. Using the Arduinomorse library in this case was problematic, because it was not possible (as far as I could tell) to adjust the WPM of the transmission on-the-fly.
W5OBM's Morse Library
The website for W5OBM's Arduino Ham Radio book has a link to another morse code library, simply called Morse. This is one that the author obtained elsewhere and modified to send correct Morse code.
This library gives the Arduino finer-grained control over the morse code that it is sending while it is in the process of sending it - that is, sending morse code is a letter-by-letter process, not a string process. For a morse code keyer with a speed control knob, we need to have more interactive control over the sending speed, and that's what the Morse library does.
LCD Display
Powering an LCD display with an Arduino.
Arduino Plus Wifi
I bought a couple of 4-pin Wifi cards to connect with an Arduino board to add wifi to some Arduino projects. We'll see how that goes. Here's a photo of one of the chips:
ESP8266 Chip
This is an ESP8266 chip, which is a serial-over-wifi chip. More information about this product: http://www.vetco.net/catalog/product_info.php?products_id=16958
Documentation for this product: http://www.vetco.net/catalog/product_info.php?products_id=16958
More information on projects and interfacing with it: http://www.seeedstudio.com/wiki/WiFi_Serial_Transceiver_Module
Manufacturer Expressif provides a nice set of pages with information/discussion/project ideas: http://bbs.espressif.com/
These are actually pretty nifty chips, much more nifty than I originally thought: you can hook up a GPIO to the chip, and have it act as a standalone chip running an application on its own.
From their page: "Our ESP8266 Wifi Module is a low-cost and easy-to-use alternative to expensive wifi shields. This module is built around a powerful onboard microprocessor that features a built-in TCP/IP stack which handles all of the heavy lifting - leaving your Arduino free to communicate using simple serial and AT commands."
Serial Interface to Wifi Chip
To interface with the wifi chip via an Arduino, a Raspberry Pi, or a computer, you can use a serial connection.
The serial connection consists of a ground and voltage pin, and two other pins for data.
Useful Hardware
You will need some hardware to talk to the wifi chip to program it. Specifically, you need a converter to turn 5V logic signals into 3.3V logic signals. You also need a separate power source for the wireless chip to ensure it can draw the full 300 mA it requires.
USB-to-Serial TTL converter:
- good for debugging via serial, doing one-off tasks via a computer
- advantages: separate power supply
- disadvantages: you can only interface with the wifi chip via the computer
USB to serial TTL chip:
- this is necessary for you to interface with the wifi chip with any ol serial device
- advantages: allows you to use a Raspberry Pi or an Arduino
- disadvantages: may require soldering, so need to find the right board
bi-directional logic converter: 3.3V to 5V (very cheap): https://www.sparkfun.com/products/12009
3.3V to 5V analog how-to, guide, tips and tricks: http://www.newark.com/pdfs/techarticles/microchip/3_3vto5vAnalogTipsnTricksBrchr.pdf
usb-to-serial TTL usb converter hardware: https://www.adafruit.com/products/954
usb-to-serial TTL usb converter guide: http://villagescience.org/running-raspberry-pi-usb-serial-ttl-adapter/
sparkfun version of the esp8266 (more pins?): https://learn.sparkfun.com/tutorials/esp8266-thing-hookup-guide/hardware-overview
another version with more pins: http://reflowster.com/blog/2015/05/11/esp8266.html
github library: https://github.com/willdurand/EspWiFi/blob/master/EspWiFi.h
almost exactly the same hardware, using a serial-to-TTL converter: http://williamdurand.fr/2015/03/17/playing-with-a-esp8266-wifi-module/
esp8266 wiki: http://www.esp8266.com/wiki/doku.php?id=getting-started-with-the-esp8266
This page [1] works by connecting an output signal from the Arduino to a USB-TTL serial converter chip. This signal is then sent back to the Arduino. The signal is (presumably) routed around to the Arudino's TX pin, and the Arduino's TX pin is hooked up to the Wifi chip's RX pin. Similarly, the Arduino's RX pin is hooked up to the Wifi chip's TX pin. This way, serial signals are routed through the USB-TTL converter.
#include <SoftwareSerial.h>
#define SSID "xxxxxxxx"
#define PASS "xxxxxxxx"
#define DST_IP "220.181.111.85" //baidu.com
SoftwareSerial dbgSerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
Serial.setTimeout(5000);
dbgSerial.begin(9600); //can't be faster than 19200 for softserial
dbgSerial.println("ESP8266 Demo");
//test if the module is ready
Serial.println("AT+RST");
delay(1000);
if(Serial.find("ready"))
{
dbgSerial.println("Module is ready");
}
else
{
dbgSerial.println("Module have no response.");
while(1);
}
delay(1000);
//connect to the wifi
boolean connected=false;
for(int i=0;i<5;i++)
{
if(connectWiFi())
{
connected = true;
break;
}
}
if (!connected){while(1);}
delay(5000);
//print the ip addr
/*Serial.println("AT+CIFSR");
dbgSerial.println("ip address:");
while (Serial.available())
dbgSerial.write(Serial.read());*/
//set the single connection mode
Serial.println("AT+CIPMUX=0");
}
void loop()
{
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += DST_IP;
cmd += "\",80";
Serial.println(cmd);
dbgSerial.println(cmd);
if(Serial.find("Error")) return;
cmd = "GET / HTTP/1.0\r\n\r\n";
Serial.print("AT+CIPSEND=");
Serial.println(cmd.length());
if(Serial.find(">"))
{
dbgSerial.print(">");
}else
{
Serial.println("AT+CIPCLOSE");
dbgSerial.println("connect timeout");
delay(1000);
return;
}
Serial.print(cmd);
delay(2000);
//Serial.find("+IPD");
while (Serial.available())
{
char c = Serial.read();
dbgSerial.write(c);
if(c=='\r') dbgSerial.print('\n');
}
dbgSerial.println("====");
delay(1000);
}
boolean connectWiFi()
{
Serial.println("AT+CWMODE=1");
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASS;
cmd+="\"";
dbgSerial.println(cmd);
Serial.println(cmd);
delay(2000);
if(Serial.find("OK"))
{
dbgSerial.println("OK, Connected to WiFi.");
return true;
}else
{
dbgSerial.println("Can not connect to the WiFi.");
return false;
}
}
Morse Code Generator
This project involves using the building blocks covered above - an LCD scren, the Arduinomorse library, and a piezoelectric speaker - to create a morse code generator with an Arduino Micro.
More Projects
https://learn.adafruit.com/series/learn-arduino
Flags
| Arduino all the arduino things
Arduino/Micro · Arduino/Leonardo · Arduino/Esplora
Arduino/Micro/Hello World · Arduino/Leonardo/Hello World · Arduino RGB LED
Arduino/Micro/Blink · Arduino/Leonardo/Blink
Arduino/Morse Code Libraries · Arduino/Morse Code Circuit · Arduino/Micro/Blink Morse Code
|