This post is about how to add support for ESP32 to Arduino IDE and how to upload a sample Arduino sketch to NodeMCU-32S.
For info. on how to update an already installed Arduino-ESP32 support package, please visit http://wei48221.blogspot.tw/2018/04/arduino-esp32-how-to-update-to-latest.html.
Below is the NodeMCU-32S module used for this post.
This blog is for keeping my study notes, sharing knowledge and showing the products of my study.. I welcome your feedback...
Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts
2017/11/18
2017/06/26
2017/06/10
Current rating info. for some of the popular boards.
This post is a short summary of the source and sink current of some of the popular boards.
2017/06/06
2017/06/03
ESP-01 - how to build a simple web server using Arduino - part 2 of 2
This is the second part of a 2 parts series on how to build a simple web server using ESP-01 and Arduino. The first part of this post is at http://wei48221.blogspot.tw/2017/06/esp-01-how-to-build-simple-web-server.html.
The Schematics
It's basically the same as that for the previous post except there is a 220 ohm resister and LED attached in series to GPIO2.
The Schematics
It's basically the same as that for the previous post except there is a 220 ohm resister and LED attached in series to GPIO2.
ESP-01 - how to build a simple web server using Arduino - part 1 of 2
This is the first of a 2-part series on how to build a simple web server using ESP-01 and Arduino. The second part of this post is at http://wei48221.blogspot.tw/2017/06/esp-01-how-to-build-simple-web-server_3.html.
The Schematics
First, wire up ESP-01 with CP-2102 as shown below.
The Schematics
First, wire up ESP-01 with CP-2102 as shown below.
2017/06/02
ESP-01 - how to setup Arduino IDE and upload and run Arduino sketch
This post is about how to develop software for ESP-01 using Arduino and Arduino IDE.
Install the board support package
1. Check the version of the Arduino IDE and whether it's from Arduino.cc or Arduino.org.
For more detail, see https://www.hackster.io/rayburne/esp8266-01-using-arduino-ide-67a124
Install the board support package
1. Check the version of the Arduino IDE and whether it's from Arduino.cc or Arduino.org.
For more detail, see https://www.hackster.io/rayburne/esp8266-01-using-arduino-ide-67a124
2016/10/03
Arduino - String Operation - strncpy(), strcpy(), and toCharArray()
Here is an example of how to use strncpy(), strcpy(), and toCharArray().
Code
Code
Arduino - Getting the ASCII code of character or string
Here is an example of how to get the ASCII code of a character or a string.
Code
Code
2016/09/20
Arduino - Converting floating number into string using the dtostrf() function
This is a quick example of how to convert floating number to string in Arduino using the dtostrf() function.
Code
Code
2016/09/18
App Inventor 2 + Arduino - Controlling Arduino via Bluetooth using an Android Phone
This is a simple example on how to control the on/off of the LED attached to pin 13 of an Arduino Uno board using an Android App. developed using MIT App Inventor 2.
Schematic
- HC-06 RXD -> Arduino Uno Pin 3
- HC-06 TXD -> Arduino Uno Pin 2
- HC-06 GND -> Arduino Uno GND
- HC-06 VCC -> Arduino Uno 5V
Schematic
- HC-06 RXD -> Arduino Uno Pin 3
- HC-06 TXD -> Arduino Uno Pin 2
- HC-06 GND -> Arduino Uno GND
- HC-06 VCC -> Arduino Uno 5V
2016/08/22
Arduino Programming Tip - Type Conversion (Byte to String)
Below is a quick example on how to convert from Byte to String in Arduino.
**Code**
String input = "128ABCD";
byte id = 128;
String str = String(id); // Converting id from byte-type into string-type
void setup() {
Serial.begin(9600); // Starts the serial communication
}
// The function below is from http://playground.arduino.cc/Main/FindText
// If the search String is found its position is returned, otherwise -1 is returned.
int find_text(String needle, String haystack) {
int foundpos = -1;
for (int i = 0; i <= haystack.length() - needle.length(); i++) {
if (haystack.substring(i,needle.length()+i) == needle) {
foundpos = i;
}
}
return foundpos;
}
void loop() {
Serial.print("Input String = ");
Serial.println(input);
if (find_text("128", input) != -1) Serial.println("128 is in the string");
Serial.print("ID = ");
Serial.println(id);
Serial.print("str = ");
Serial.println(str);
Serial.print("Find str in input string - ");
if (find_text(str, input) != -1) Serial.println("128 is in the string");
delay(2000);
}
**Result**
**Code**
String input = "128ABCD";
byte id = 128;
String str = String(id); // Converting id from byte-type into string-type
void setup() {
Serial.begin(9600); // Starts the serial communication
}
// The function below is from http://playground.arduino.cc/Main/FindText
// If the search String is found its position is returned, otherwise -1 is returned.
int find_text(String needle, String haystack) {
int foundpos = -1;
for (int i = 0; i <= haystack.length() - needle.length(); i++) {
if (haystack.substring(i,needle.length()+i) == needle) {
foundpos = i;
}
}
return foundpos;
}
void loop() {
Serial.print("Input String = ");
Serial.println(input);
if (find_text("128", input) != -1) Serial.println("128 is in the string");
Serial.print("ID = ");
Serial.println(id);
Serial.print("str = ");
Serial.println(str);
Serial.print("Find str in input string - ");
if (find_text(str, input) != -1) Serial.println("128 is in the string");
delay(2000);
}
**Result**
2016/08/07
How to use a hall effect sensor
This is a quick summary on how to use Hall Effect Sensor US5881 / US1881.
US1881 is a latching hall effect sensor. The sensor gives out an output HIGH (5V) voltage whenever the north pole of a magnet is brought close to it. However, even when the magnet is removed the sensor still outputs a HIGH voltage and does not go LOW (0V) until the south pole of the magnet is brought close to it. These type of sensors that latches on to a particular state are called latched hall effect sensors.
US5881 is a non-latching hall effect sensor. Here, the sensor gives an output HIGH voltage whenever the north pole of a magnet is brought close to it. And, switches LOW whenever the magnet is removed.
Wiring
Code
//Connect the output pin (pin 3) of the hall effect sensor to Arduino digital pin 2
#define Hall_Sensor 2
void setup()
{
Serial.begin(9600);
pinMode(Hall_Sensor, INPUT);
}
void loop()
{
while (digitalRead(Hall_Sensor) == LOW) {
Serial.println("Detect");
}
}
References:
US5881 Datasheet
https://cdn-shop.adafruit.com/datasheets/US5881_rev007.pdf
US1881 Datasheet
https://www.sparkfun.com/datasheets/Components/General/Hall-US1881EUA.pdf
ARDUINO HALL EFFECT SENSOR TUTORIAL: THE EASY WAY
http://diyhacking.com/arduino-hall-effect-sensor-tutorial/
Hall effect sensor - US5881LUA
https://www.adafruit.com/product/158
US1881 is a latching hall effect sensor. The sensor gives out an output HIGH (5V) voltage whenever the north pole of a magnet is brought close to it. However, even when the magnet is removed the sensor still outputs a HIGH voltage and does not go LOW (0V) until the south pole of the magnet is brought close to it. These type of sensors that latches on to a particular state are called latched hall effect sensors.
US5881 is a non-latching hall effect sensor. Here, the sensor gives an output HIGH voltage whenever the north pole of a magnet is brought close to it. And, switches LOW whenever the magnet is removed.
Wiring
Code
//Connect the output pin (pin 3) of the hall effect sensor to Arduino digital pin 2
#define Hall_Sensor 2
void setup()
{
Serial.begin(9600);
pinMode(Hall_Sensor, INPUT);
}
void loop()
{
while (digitalRead(Hall_Sensor) == LOW) {
Serial.println("Detect");
}
}
References:
US5881 Datasheet
https://cdn-shop.adafruit.com/datasheets/US5881_rev007.pdf
US1881 Datasheet
https://www.sparkfun.com/datasheets/Components/General/Hall-US1881EUA.pdf
ARDUINO HALL EFFECT SENSOR TUTORIAL: THE EASY WAY
http://diyhacking.com/arduino-hall-effect-sensor-tutorial/
Hall effect sensor - US5881LUA
https://www.adafruit.com/product/158
2016/07/07
Single channel 12V / 24V, 5A(?) brush DC motor control board with H/W select-able PWM sources
This board is design for the DIY Filament Extruder (click here to see the project).
3 of this board are needed to control the speed of the 3 motors of the filament winder assembly (under construction).
The board is of the same size as Arduino Uno. The position of the 4 holes on the board match the locations of the 4 holes on the Arduino Uno board.
Theoretically, the board can handle 12V or 24V DC motor with maximum current of 5A. Will need to test it to see if it could actually handle it.
Run "run length-freq-ri" in Eagle PCB to see the length and maximum current for each trace.
Note, Cu thickness = 0.035mm = 13.78mil (~1 oz copper, 14mil = 1 oz copper).
Demo Videos
DC 12V/24V Brush Motor Speed Control with Arduino Uno
DC 12V/24V Brush Motor Speed Control with 555 Timer
Note,
This board doesn't have built-in mechanism to control the rotation direction of the motor. In order to control the rotation direction, a Double Pole Double Throw (DPDT) Switch needs to be installed between the PWM_OUT and the Motor for the User to manually control the direction.
Next Steps
- Have the board manufactured by a PCB house;
- Develop a H-bridge DC motor speed and direction control board using MOSFETs.
References
Eagle QuickTip: Measure Trace Length (and more)
https://blog.adafruit.com/2012/02/13/eagle-quicktip-measure-trace-length-and-more/
Simplest Method to Make a Motor Turn Off, Turn On, Go Forwards, and Go Backwards
http://www.robotroom.com/DPDT-Bidirectional-Motor-Switch.html
3 of this board are needed to control the speed of the 3 motors of the filament winder assembly (under construction).
The board is of the same size as Arduino Uno. The position of the 4 holes on the board match the locations of the 4 holes on the Arduino Uno board.
Theoretically, the board can handle 12V or 24V DC motor with maximum current of 5A. Will need to test it to see if it could actually handle it.
Run "run length-freq-ri" in Eagle PCB to see the length and maximum current for each trace.
Note, Cu thickness = 0.035mm = 13.78mil (~1 oz copper, 14mil = 1 oz copper).
Demo Videos
DC 12V/24V Brush Motor Speed Control with Arduino Uno
DC 12V/24V Brush Motor Speed Control with 555 Timer
Note,
This board doesn't have built-in mechanism to control the rotation direction of the motor. In order to control the rotation direction, a Double Pole Double Throw (DPDT) Switch needs to be installed between the PWM_OUT and the Motor for the User to manually control the direction.
Next Steps
- Have the board manufactured by a PCB house;
- Develop a H-bridge DC motor speed and direction control board using MOSFETs.
References
Eagle QuickTip: Measure Trace Length (and more)
https://blog.adafruit.com/2012/02/13/eagle-quicktip-measure-trace-length-and-more/
Simplest Method to Make a Motor Turn Off, Turn On, Go Forwards, and Go Backwards
http://www.robotroom.com/DPDT-Bidirectional-Motor-Switch.html
2016/06/21
Collection of MOSFET / BJT Tips
Here is a list of links to the sites that I consider quite useful when working with MOSFET / BJT. More will be added as I venture further into this field.
MOSFET
How to Build an Inverter with a Transistor
http://www.learningaboutelectronics.com/Articles/Transistor-inverter-circuit.php
H-Bridge Motor Control with Power MOSFETS
http://www.bristolwatch.com/ele/h_bridge.htm
Need help with MOSFET h-bridge; gets hot when using PWM frequency of ~500Hz.
http://www.instructables.com/answers/Need-help-with-MOSFET-h-bridge-gets-hot-when-usin/
What is the purpose of “MOSFET driver” IC's
http://electronics.stackexchange.com/questions/3348/what-is-the-purpose-of-mosfet-driver-ics
**MOSFET H-Bridge heating up with PWM**
http://forum.allaboutcircuits.com/threads/mosfet-h-bridge-heating-up-with-pwm.74159/
**Understanding MOSFET Current Ratings** <- Very good. Must read!!
http://www.mcmanis.com/chuck/Robotics/projects/esc2/FET-power.html
**Bi-directional Level Shifter Using 2N7000
http://husstechlabs.com/support/tutorials/bi-directional-level-shifter/
BJT
H-Bridge Tutorial
http://nathandumont.com/blog/h-bridge-tutorial
H-Bridge on a Breadboard
http://www.instructables.com/id/H-Bridge-on-a-Breadboard/
**Tutorial: How to design a transistor circuit that controls low-power devices** <-- Very good one!!
http://electronicsforu.com/resources/tutorial-design-transistor-circuit-controls-low-power-devices
Other Relevant References
H bridge
https://en.wikipedia.org/wiki/H_bridge
Using the L293D to drive large motors
http://www.electro-tech-online.com/threads/using-the-l293d-to-drive-large-motors.11952/
Make an 8-amp Dual Motor Controller For $40
http://www.instructables.com/id/Make-an-8-amp-Motor-Controller/?ALLSTEPS
Arduino Power, Current, and Voltage Limitations
http://www.electricrcaircraftguy.com/2014/02/arduino-power-current-and-voltage.html
MOSFET
How to Build an Inverter with a Transistor
http://www.learningaboutelectronics.com/Articles/Transistor-inverter-circuit.php
H-Bridge Motor Control with Power MOSFETS
http://www.bristolwatch.com/ele/h_bridge.htm
Need help with MOSFET h-bridge; gets hot when using PWM frequency of ~500Hz.
http://www.instructables.com/answers/Need-help-with-MOSFET-h-bridge-gets-hot-when-usin/
What is the purpose of “MOSFET driver” IC's
http://electronics.stackexchange.com/questions/3348/what-is-the-purpose-of-mosfet-driver-ics
**MOSFET H-Bridge heating up with PWM**
http://forum.allaboutcircuits.com/threads/mosfet-h-bridge-heating-up-with-pwm.74159/
**Understanding MOSFET Current Ratings** <- Very good. Must read!!
http://www.mcmanis.com/chuck/Robotics/projects/esc2/FET-power.html
**Bi-directional Level Shifter Using 2N7000
http://husstechlabs.com/support/tutorials/bi-directional-level-shifter/
BJT
H-Bridge Tutorial
http://nathandumont.com/blog/h-bridge-tutorial
H-Bridge on a Breadboard
http://www.instructables.com/id/H-Bridge-on-a-Breadboard/
**Tutorial: How to design a transistor circuit that controls low-power devices** <-- Very good one!!
http://electronicsforu.com/resources/tutorial-design-transistor-circuit-controls-low-power-devices
Other Relevant References
H bridge
https://en.wikipedia.org/wiki/H_bridge
Using the L293D to drive large motors
http://www.electro-tech-online.com/threads/using-the-l293d-to-drive-large-motors.11952/
Make an 8-amp Dual Motor Controller For $40
http://www.instructables.com/id/Make-an-8-amp-Motor-Controller/?ALLSTEPS
Arduino Power, Current, and Voltage Limitations
http://www.electricrcaircraftguy.com/2014/02/arduino-power-current-and-voltage.html
2016/06/19
How to select MOSFET for Arduino / Raspberry Pi projects
This is a quick summary of the info. on how to select MOSFET for Arduino / Raspberry Pi projects. MOSFET is a very useful device for controlling device that consumes current and/or voltage beyond the output current / voltage capacity of Arduino / Raspberry Pi. In addition, it's also very useful in applications that call for fast / frequent turn on / off of the connected device.
2016/06/14
How to use Unojoy with Arduino Uno
This is a quick summary of how to use Unojoy with Arduino Uno.
Preparing the necessary software
1. Download the code from here.
Pick "UnoJoyWin-21Feb2013.zip" as it's the latest version for MS-Windows.
2. Unzip the downloaded file into a folder. In the folder, the key files are in the 3 folders highlighted below.
Note,
In the ATmega8u2Code\HexFiles folder, there are "UnoJoy.hex" and "Arduino-usbserial-uno.hex". Burning the "UnoJoy.hex" into the Atmega16U2 of an Arduino Uno board will turn the board into a HID Joystick. Burning the "Arduino-usbserial-uno.hex" into the Atmega16U2 of the same board will turn in back to an Arduino Uno board.
The procedure for burning "UnoJoy.hex" and "Arduino-usbserial-uno.hex" into the Atmega16U2 of an Arduino Uno board can be found in my previous post here.
The sample Arduino sketch and its library are located under the UnoJoyArduinoSample folder.
The program for verifying the code developed to take advantage of Unojoy is located under the UnoJoyProcessingVisualizer folder.
Compile and upload the sample sketch
Compile and upload the "UnoJoyArduinoSample.ino" sketch in the UnoJoyArduinoSample folder to the Arduino Uno board.
Verify the sketch
Launch the "UnoJoyProcessingVisualizer.exe" program in the UnoJoyProcessingVisualizer folder. A window similar to the one below will appear.
Plug one end of a wire into the GND and the other end into digital pin 2 ~ 12 and analog pin A4 ~ A5 to see the corresponding button lights up in the window.
For the joystick portion, please refer to the article - Interfacing a Joystick.
After checking the sketch and seeing everything is working as planned. It's time to turn the Arduino Uno board into a joystick.
Flashing the "UnoJoy.hex" into the ATMega16U2 of the Arduino Uno board
Please refer to the "Burning the firmware into atmega16u2" section of my previous post for detail instruction.
After burning the "UnoJoy.hex" and unplug and plug the USB cable, there is now a new device called "HID-compliant game controller" in Windows Device Manager.
Note, To upload sketch to the Arduino Uno board again, burn the "Arduino-usbserial-uno.hex" into the atmega16u2.
Reference
unojoy - GettingStarted.wiki
https://code.google.com/archive/p/unojoy/wikis/GettingStarted.wiki
Arduino UnoJoy gamepad (Windows, XBox emulation)
https://www.youtube.com/watch?v=GrO8ZmxbOyI
Arduino wireless gamepad (UnoJoy)
https://www.youtube.com/watch?v=cZc-23NjNHY
Interfacing a Joystick
https://www.arduino.cc/en/Tutorial/JoyStick
Preparing the necessary software
1. Download the code from here.
Pick "UnoJoyWin-21Feb2013.zip" as it's the latest version for MS-Windows.
2. Unzip the downloaded file into a folder. In the folder, the key files are in the 3 folders highlighted below.
Note,
In the ATmega8u2Code\HexFiles folder, there are "UnoJoy.hex" and "Arduino-usbserial-uno.hex". Burning the "UnoJoy.hex" into the Atmega16U2 of an Arduino Uno board will turn the board into a HID Joystick. Burning the "Arduino-usbserial-uno.hex" into the Atmega16U2 of the same board will turn in back to an Arduino Uno board.
The procedure for burning "UnoJoy.hex" and "Arduino-usbserial-uno.hex" into the Atmega16U2 of an Arduino Uno board can be found in my previous post here.
The sample Arduino sketch and its library are located under the UnoJoyArduinoSample folder.
The program for verifying the code developed to take advantage of Unojoy is located under the UnoJoyProcessingVisualizer folder.
Compile and upload the sample sketch
Compile and upload the "UnoJoyArduinoSample.ino" sketch in the UnoJoyArduinoSample folder to the Arduino Uno board.
Verify the sketch
Launch the "UnoJoyProcessingVisualizer.exe" program in the UnoJoyProcessingVisualizer folder. A window similar to the one below will appear.
Plug one end of a wire into the GND and the other end into digital pin 2 ~ 12 and analog pin A4 ~ A5 to see the corresponding button lights up in the window.
For the joystick portion, please refer to the article - Interfacing a Joystick.
After checking the sketch and seeing everything is working as planned. It's time to turn the Arduino Uno board into a joystick.
Flashing the "UnoJoy.hex" into the ATMega16U2 of the Arduino Uno board
Please refer to the "Burning the firmware into atmega16u2" section of my previous post for detail instruction.
After burning the "UnoJoy.hex" and unplug and plug the USB cable, there is now a new device called "HID-compliant game controller" in Windows Device Manager.
Note, To upload sketch to the Arduino Uno board again, burn the "Arduino-usbserial-uno.hex" into the atmega16u2.
Reference
unojoy - GettingStarted.wiki
https://code.google.com/archive/p/unojoy/wikis/GettingStarted.wiki
Arduino UnoJoy gamepad (Windows, XBox emulation)
https://www.youtube.com/watch?v=GrO8ZmxbOyI
Arduino wireless gamepad (UnoJoy)
https://www.youtube.com/watch?v=cZc-23NjNHY
Interfacing a Joystick
https://www.arduino.cc/en/Tutorial/JoyStick
2016/06/13
How to turn Arduino Uno into HID Keyboard - Part 2 of 2
This post is the second part of How to turn Arduino Uno into HID Keyboard tutorial. The first part can be found here.
To test the HID Keyboard, I want to use the "Random Key/Random Delay" code from http://mitchtech.net/arduino-usb-hid-keyboard/ because of its simplicity and there is no wiring involved.
/* Arduino USB HID Keyboard Demo
* Random Key/Random Delay
*/
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
delay(200);
}
void loop()
{
int randomChar = random(4, 130);
long randomDelay = random(1000, 10000);
delay(randomDelay);
buf[2] = randomChar; // Random character
Serial.write(buf, 8); // Send keypress
releaseKey();
}
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
}
To use the code, follow the below procedure (assuming the ATMega16U2 has "Arduino-usbserial-uno.hex" in it):
1. Copy and past the above code into Arduino IDE;
2. Compile and upload the code to Arduino Uno;
3.. Follow the instruction in my previous post to burn the "Arduino-keyboard-0.3.hex" into ATMega16U2;
4. Unplug the USB cable and plug it back in;
5. Launch a word editing program (MS-Word, UltraEdit, etc.) and wait to see random character appears at random interval.
When you are done with the test, follow the instruction in my previous post to burn the "Arduino-usbserial-uno.hex" back into ATMega16U2 then unplug the USB cable and plug it back to make the board a normal Arduino Uno again.
Reference
Arduino USB HID Keyboard
http://mitchtech.net/arduino-usb-hid-keyboard/
To test the HID Keyboard, I want to use the "Random Key/Random Delay" code from http://mitchtech.net/arduino-usb-hid-keyboard/ because of its simplicity and there is no wiring involved.
/* Arduino USB HID Keyboard Demo
* Random Key/Random Delay
*/
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
delay(200);
}
void loop()
{
int randomChar = random(4, 130);
long randomDelay = random(1000, 10000);
delay(randomDelay);
buf[2] = randomChar; // Random character
Serial.write(buf, 8); // Send keypress
releaseKey();
}
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
}
To use the code, follow the below procedure (assuming the ATMega16U2 has "Arduino-usbserial-uno.hex" in it):
1. Copy and past the above code into Arduino IDE;
2. Compile and upload the code to Arduino Uno;
3.. Follow the instruction in my previous post to burn the "Arduino-keyboard-0.3.hex" into ATMega16U2;
4. Unplug the USB cable and plug it back in;
5. Launch a word editing program (MS-Word, UltraEdit, etc.) and wait to see random character appears at random interval.
When you are done with the test, follow the instruction in my previous post to burn the "Arduino-usbserial-uno.hex" back into ATMega16U2 then unplug the USB cable and plug it back to make the board a normal Arduino Uno again.
Reference
Arduino USB HID Keyboard
http://mitchtech.net/arduino-usb-hid-keyboard/
2016/06/11
How to turn Arduino Uno into HID Keyboard - Part 1 of 2
This is the first of a two parts series. This part is to provide a brief overview of HID concept and how to prepare and turn an Arduino Uno into a HID device (in this case, a HID Keyboard).
The 2nd part will be dealing with the coding of an Arduino sketch to send keystrokes to the connected PC over the USB port and some other stuff. The 2nd part can be found here.
Brief Overview
The Arduino USB HID keyboard is implemented by sending a 8-byte long "Keyboard Report Buffer" via the USB that connects the PC and the Arduino.
The format of the Keyboard Report Buffer is as follow.
The format of the Modifier Keys (Byte 0) is as follow.
As for keycode 1 ~ 6, they can be found in the Keyboard Scan Codes in the reference section of this post.
Preparing the Arduino and the needed firmware and tools
Note, the instructions below are for Arduino Uno and MS-Windows 8.1.
1. Check the Arduino board for its version and whether the USB Serial chip used is supported by the DFU tool.
If yours is R1, please follow the instruction here to modify it.
2. Download and save the "Arduino-usbserial.hex" in a safe location. This firmware needs to be in atmega16u2 for burning sketch unto the Arduino board using Arduino IDE and USB cable.
Here is the download link.
https://dl.dropboxusercontent.com/u/1816557/Arduino-usbserial-uno.hex
Note,
I think there is a missing Arduino-usbserial.hex in at the below github site.
https://github.com/arduino/Arduino/tree/master/hardware/arduino/avr/firmwares/atmegaxxu2/arduino-usbserial
3. Download a DFU Programmer from http://www.atmel.com/tools/flip.aspx.
Since I already have Java Run Time installed on my PC, I downloaded the one without Java Run Time.
4. Download the Keyboard HID firmware "Arduino-keyboard-0.3.hex" from here and save it to a safe location. After this firmware is written into atmega16u2, the Arduino Uno board will be viewed as a USB keyboard when it's plugged into a PC.
Burning the firmware into atmega16u2
1. Put the atmega16u2 in DFU (Device Firmware Update) mode by briefly shorting the 2 leftmost ICSP headers next to the USB port.
2. Install the ATmega16U2 DFU driver.
Note, the driver needs to be installed for Flip to communicate with ATmega16U2 on the Arduino Uno board.
On the computer, the driver "atmel_usb_dfu.inf" can be found under C:\Program Files (x86)\Atmel\Flip 3.4.7\usb.
3. Launch Flip. Select "Device", then select ATmega16U2 from the list.
4. Left click on the "Select a Communication Medium", left click on USB, left click on Open. The USB:ON indication on the lower right hand corner indicates Flip is now connected to ATmega16U2.
5. Go to File, Load HEX File, and select the Hex file to be written into ATmega16U2.
In this case, I choose to burn the "Arduino-keyboard-0.3.hex".
6. Click on Run to erase the existing firmware (Earse), write the new firmware (Program), and verify the written firmware (Verify) in ATmega16U2.
7. Unplug the USB cable that connects the Arduino Uno and the PC then plug the cable back in again. Go to Device Manager and there is now a HID Keyboard Device under "Keyboard".
Below is the Device Manager screen when a normal Arduino Uno is plugged in. Note that there is no HID Keyboard Device under Keyboard and an Arduino Uno is shown under COM & LPT
To burn the USB Serial firmware back to ATmega16U2 (turn the HID Keyboard Device back to a normal Arduino Uno board), simply repeat step 1 to 7 above except step 5. In step 5, select the previous saved "Arduino-usbserial-uno.hex" instead of "Arduino-keyboard-0.3.hex".
After "Arduino-usbserial-uno.hex" is written into ATmega16U2, close Flip, remove USB cable then plug it back in. The Windows OS will detect it as a new device and look for its driver. Very soon it will recognize it as an Arduino Uno and uses the already installed driver to support it. After that, the board is ready for uploading sketch via the Arduino IDE again.
Note,
Remember to short the 2 leftmost ICSP headers next to the USB port before launching Flip.
After shorting the pins, there will be an Atmel USB Devices in the Device Manager and no HID Keyboard Device. The ATmega16U2 is now ready to be flashed with new firmware.
Reference
Keyboard Scan Codes
The tables below are from P53 ~ P59 of the "USB HID Usage Tables". This document can be downloaded at http://www.usb.org/developers/hidpage/Hut1_12v2.pdf.
DFU Related References
Updating the Atmega8U2 and 16U2 on an Uno or Mega2560 using DFU
https://www.arduino.cc/en/Hacking/DFUProgramming8U2
DFU programming the atmega16u2 on the Arduino UNO R3
http://bartruffle.blogspot.tw/2013/09/dfu-programming-atmega16u2-on-arduino.html
HID Keyboard Related References
List of hex keyboard scan codes and USB HID keyboard documentation
http://stackoverflow.com/questions/27075328/list-of-hex-keyboard-scan-codes-and-usb-hid-keyboard-documentation
HID USB Keyboard
http://stackoverflow.com/questions/24055687/hid-usb-keyboard
USB Device Class Definition for Human Interface Devices (HID)
http://www.usb.org/developers/hidpage/HID1_11.pdf
HID Keyboard Related Arduino Sketch References
Arduino USB HID Keyboard
http://mitchtech.net/arduino-usb-hid-keyboard/
Arduino UNO Keyboard HID part 2
http://hunt.net.nz/users/darran/weblog/faf5e/Arduino_UNO_Keyboard_HID_part_2.html
--------------------------------------------------------------------------------------------------------------------------
HID Joystick Related Arduino Sketch References
Arduino UNO Big Joystick HID firmware
http://hunt.net.nz/users/darran/weblog/15f92/Arduino_UNO_Big_Joystick_HID_firmware.html
unojoy - GettingStarted.wiki
https://code.google.com/archive/p/unojoy/wikis/GettingStarted.wiki
Arduino wireless gamepad (UnoJoy)
https://www.youtube.com/watch?v=cZc-23NjNHY
--------------------------------------------------------------------------------------------------------------------------
Misc. Info.
PPM / CPPM Receiver
http://www.deviationtx.com/forum/3-feedback-questions/1845-ppm-cppm-receiver
Arduino + 2 Servos + Thumbstick (joystick)
http://www.instructables.com/id/Arduino-2-Servos-Thumbstick-joystick/step3/Connecting-the-thumbstick-joystick/
Arduino thumbstick controller
http://www.instructables.com/id/Arduino-thumbstick-controller/
How to Restore the Arduino UNO R3 ATmega16U2 Firmware Using the Arduino IDE
http://www.instructables.com/id/How-to-Restore-the-Arduino-UNO-R3-ATmega16U2-Firmw/
The 2nd part will be dealing with the coding of an Arduino sketch to send keystrokes to the connected PC over the USB port and some other stuff. The 2nd part can be found here.
Brief Overview
The Arduino USB HID keyboard is implemented by sending a 8-byte long "Keyboard Report Buffer" via the USB that connects the PC and the Arduino.
The format of the Keyboard Report Buffer is as follow.
The format of the Modifier Keys (Byte 0) is as follow.
As for keycode 1 ~ 6, they can be found in the Keyboard Scan Codes in the reference section of this post.
Preparing the Arduino and the needed firmware and tools
Note, the instructions below are for Arduino Uno and MS-Windows 8.1.
1. Check the Arduino board for its version and whether the USB Serial chip used is supported by the DFU tool.
Mine is R3 (no need to modify it)
If yours is R1, please follow the instruction here to modify it.
This board is using MEGA16U2
MEGA16U2 is on the support list
2. Download and save the "Arduino-usbserial.hex" in a safe location. This firmware needs to be in atmega16u2 for burning sketch unto the Arduino board using Arduino IDE and USB cable.
Here is the download link.
https://dl.dropboxusercontent.com/u/1816557/Arduino-usbserial-uno.hex
I think there is a missing Arduino-usbserial.hex in at the below github site.
https://github.com/arduino/Arduino/tree/master/hardware/arduino/avr/firmwares/atmegaxxu2/arduino-usbserial
3. Download a DFU Programmer from http://www.atmel.com/tools/flip.aspx.
Since I already have Java Run Time installed on my PC, I downloaded the one without Java Run Time.
4. Download the Keyboard HID firmware "Arduino-keyboard-0.3.hex" from here and save it to a safe location. After this firmware is written into atmega16u2, the Arduino Uno board will be viewed as a USB keyboard when it's plugged into a PC.
Burning the firmware into atmega16u2
1. Put the atmega16u2 in DFU (Device Firmware Update) mode by briefly shorting the 2 leftmost ICSP headers next to the USB port.
2. Install the ATmega16U2 DFU driver.
Note, the driver needs to be installed for Flip to communicate with ATmega16U2 on the Arduino Uno board.
On the computer, the driver "atmel_usb_dfu.inf" can be found under C:\Program Files (x86)\Atmel\Flip 3.4.7\usb.
3. Launch Flip. Select "Device", then select ATmega16U2 from the list.
4. Left click on the "Select a Communication Medium", left click on USB, left click on Open. The USB:ON indication on the lower right hand corner indicates Flip is now connected to ATmega16U2.
5. Go to File, Load HEX File, and select the Hex file to be written into ATmega16U2.
In this case, I choose to burn the "Arduino-keyboard-0.3.hex".
6. Click on Run to erase the existing firmware (Earse), write the new firmware (Program), and verify the written firmware (Verify) in ATmega16U2.
7. Unplug the USB cable that connects the Arduino Uno and the PC then plug the cable back in again. Go to Device Manager and there is now a HID Keyboard Device under "Keyboard".
Below is the Device Manager screen when a normal Arduino Uno is plugged in. Note that there is no HID Keyboard Device under Keyboard and an Arduino Uno is shown under COM & LPT
To burn the USB Serial firmware back to ATmega16U2 (turn the HID Keyboard Device back to a normal Arduino Uno board), simply repeat step 1 to 7 above except step 5. In step 5, select the previous saved "Arduino-usbserial-uno.hex" instead of "Arduino-keyboard-0.3.hex".
After "Arduino-usbserial-uno.hex" is written into ATmega16U2, close Flip, remove USB cable then plug it back in. The Windows OS will detect it as a new device and look for its driver. Very soon it will recognize it as an Arduino Uno and uses the already installed driver to support it. After that, the board is ready for uploading sketch via the Arduino IDE again.
Note,
Remember to short the 2 leftmost ICSP headers next to the USB port before launching Flip.
After shorting the pins, there will be an Atmel USB Devices in the Device Manager and no HID Keyboard Device. The ATmega16U2 is now ready to be flashed with new firmware.
Reference
Keyboard Scan Codes
The tables below are from P53 ~ P59 of the "USB HID Usage Tables". This document can be downloaded at http://www.usb.org/developers/hidpage/Hut1_12v2.pdf.
Updating the Atmega8U2 and 16U2 on an Uno or Mega2560 using DFU
https://www.arduino.cc/en/Hacking/DFUProgramming8U2
DFU programming the atmega16u2 on the Arduino UNO R3
http://bartruffle.blogspot.tw/2013/09/dfu-programming-atmega16u2-on-arduino.html
HID Keyboard Related References
List of hex keyboard scan codes and USB HID keyboard documentation
http://stackoverflow.com/questions/27075328/list-of-hex-keyboard-scan-codes-and-usb-hid-keyboard-documentation
HID USB Keyboard
http://stackoverflow.com/questions/24055687/hid-usb-keyboard
USB Device Class Definition for Human Interface Devices (HID)
http://www.usb.org/developers/hidpage/HID1_11.pdf
HID Keyboard Related Arduino Sketch References
Arduino USB HID Keyboard
http://mitchtech.net/arduino-usb-hid-keyboard/
Arduino UNO Keyboard HID part 2
http://hunt.net.nz/users/darran/weblog/faf5e/Arduino_UNO_Keyboard_HID_part_2.html
--------------------------------------------------------------------------------------------------------------------------
HID Joystick Related Arduino Sketch References
Arduino UNO Big Joystick HID firmware
http://hunt.net.nz/users/darran/weblog/15f92/Arduino_UNO_Big_Joystick_HID_firmware.html
unojoy - GettingStarted.wiki
https://code.google.com/archive/p/unojoy/wikis/GettingStarted.wiki
Arduino wireless gamepad (UnoJoy)
https://www.youtube.com/watch?v=cZc-23NjNHY
--------------------------------------------------------------------------------------------------------------------------
Misc. Info.
PPM / CPPM Receiver
http://www.deviationtx.com/forum/3-feedback-questions/1845-ppm-cppm-receiver
Arduino + 2 Servos + Thumbstick (joystick)
http://www.instructables.com/id/Arduino-2-Servos-Thumbstick-joystick/step3/Connecting-the-thumbstick-joystick/
Arduino thumbstick controller
http://www.instructables.com/id/Arduino-thumbstick-controller/
How to Restore the Arduino UNO R3 ATmega16U2 Firmware Using the Arduino IDE
http://www.instructables.com/id/How-to-Restore-the-Arduino-UNO-R3-ATmega16U2-Firmw/
2016/06/07
Simple wireless instant messenger using Arduino + HC-11
This is a quick summary of a simple wireless instant messenger using Arduino + HC-11.
Wiring - Sender (Arduino Uno)
Wiring - Receiver (Arduino Nano)
Code - Sender
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //RX, TX
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
if (Serial.available() > 0){ //Read from serial monitor and send over HC-11
String input = Serial.readString();
mySerial.println(input);
}
if(mySerial.available() > 1){ //Read from HC-11 and send to serial monitor
String input = mySerial.readString();
Serial.println(input);
}
delay(5);
}
Code - Receiver
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //RX, TX
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
if (Serial.available() > 0){ //Read from serial monitor and send over HC-11
String input = Serial.readString();
mySerial.println(input);
}
if(mySerial.available() > 1){ //Read from HC-11 and send to serial monitor
String input = mySerial.readString();
Serial.println(input);
}
delay(5);
}
Reference
Long range, 1.8km, Arduino to Arduino wireless communication with the HC-12
https://www.youtube.com/watch?v=DGRPqeacJns
Wiring - Sender (Arduino Uno)
Wiring - Receiver (Arduino Nano)
Code - Sender
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //RX, TX
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
if (Serial.available() > 0){ //Read from serial monitor and send over HC-11
String input = Serial.readString();
mySerial.println(input);
}
if(mySerial.available() > 1){ //Read from HC-11 and send to serial monitor
String input = mySerial.readString();
Serial.println(input);
}
delay(5);
}
Code - Receiver
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //RX, TX
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
if (Serial.available() > 0){ //Read from serial monitor and send over HC-11
String input = Serial.readString();
mySerial.println(input);
}
if(mySerial.available() > 1){ //Read from HC-11 and send to serial monitor
String input = mySerial.readString();
Serial.println(input);
}
delay(5);
}
Reference
Long range, 1.8km, Arduino to Arduino wireless communication with the HC-12
https://www.youtube.com/watch?v=DGRPqeacJns
Subscribe to:
Posts (Atom)