KS0446 Keyestudio Frog Robot for Arduino Graphical Programming: Difference between revisions

From Keyestudio Wiki
Jump to navigation Jump to search
Line 567: Line 567:
<br>
<br>
===<span style="color:green">  Project 6: Walk </span>===
===<span style="color:green">  Project 6: Walk </span>===
<br>[[File:Ks0446图片61.png|600px|frameless]]<br>  
[[File:Ks0446图片65.png|600px|frameless|right]]
<br>
'''Circuit Design:'''<br>
After completing the robot assembly, you’ll see the 4 Servo motors on the robot are connected well to the keyestudio Nano ch340 shield. <br>
We have introduced the knowledge of how to adjust the Servo angle. <br>
In the circuit, we are going to make the 4 Servo motors switch different angles using keyestudio Nano ch340 shield, so as to operate the frog robot walk.<br>


Circuit Design
'''How it works?'''<br>
After completing the robot assembly, you’ll see the 4 Servo motors on the robot are connected well to the keyestudio Nano ch340 shield.
When design the Otto frog robot, should first design the 4 Servo motors’ position and corresponding control pins.<br>
We have introduced the knowledge of how to adjust the Servo angle.
Check the detailed instructions for servo control pins. As the figure shown below.<br>
In the circuit, we are going to make the 4 Servo motors switch different angles using keyestudio Nano ch340 shield, so as to operate the frog robot walk.
 
How it works?
When design the Otto frog robot, should first design the 4 Servo motors’ position and corresponding control pins.
Check the detailed instructions for servo control pins. As the figure shown below.
<pre>
<pre>


Line 591: Line 591:
</pre>
</pre>


Hookup Guide:
<br>
Simply stack the keyestudio Nano ch340 into the keystudio NANO shield.  
'''Hookup Guide:'''<br>
Simply stack the keyestudio Nano ch340 into the keystudio NANO shield. <br>
Connect the Servo pin to digital pin 2, 3, 4, 5 separately.
Connect the Servo pin to digital pin 2, 3, 4, 5 separately.
<br>[[File:Ks0446图片66.png|600px|frameless|]]<br>


<br>
'''Code:'''<br>
<span style="color:red">  Note: should upload the code success first, then plug in Bluetooth module. Otherwise, code upload fails.</span><br>
<br>[[File:Ks0446图片67.png|600px|frameless|]]<br>


<br>
'''Result:'''<br>
Done uploading the code, press down the Power_Switch on Nano Shield.<br>
The Otto frog robot is ready to walk 5 steps forward, back 5 steps, keep standing for 1 second, turn left for 5 steps, turn right for 5 steps, keep standing for 1 second, alternately and loop.
<br>[[File:Ks0446图片68.png|600px|frameless|]]<br>
<br>[[File:Ks0446图片61.png|600px|frameless|]]<br>


Code:
<br>
<span style="color:red"> Note: should upload the code success first, then plug in Bluetooth module. Otherwise, code upload fails.
 
 
Result
Done uploading the code, press down the Power_Switch on Nano Shield.
The Otto frog robot is ready to walk 5 steps forward, back 5 steps, keep standing for 1 second, turn left for 5 steps, turn right for 5 steps, keep standing for 1 second, alternately and loop.

Revision as of 15:28, 8 August 2019

Keyestudio Frog Robot for Arduino Graphical Programming


About the tutorial

What an amazing Otto Frog Robot is coming!
This kit provides a perfect opportunity to build your very first robot, and it makes the process of learning about robotics easy, interactive, and FUN!
The kit is based on the keyestudio nano ch340, compatible with both Arduino open-source platform and Mixly Blocks coding.
You can program your own robot to walk, dance and follow obstacle, easy to build and code. No prior tech experience required!
Through play and experimentation children can exercise computational thinking and put skills into practice that are necessary for problem solving.


Features

  • Voltage input: DC 7-12V
  • Ultrasonic module for measuring the front obstacle distance, forming obstacle avoiding system;
  • Pairing HM-10 Bluetooth module with mobile Bluetooth to navigate the frog robot;
  • Providing the mobile APP compatible with both Android and mac system;
  • The NANO shield extends 12 digital pins and 8 analog pins into 3pin header, easy to connect a couple of sensor modules for projects extension;
  • The NANO shield comes with an I2C communication pin, able to connect I2C communication module for experiment extension.


Ks0446图片2.png


Parts List

In this keyestudio frog robot kit package, you’ll receive all the components needed to build your own robot, easy to code and learn to play.

Ks0446图片3.png

Ks0446图片4.pngKs0446图片5.png



Get Started with Mixly and ARDUINO

1)Installing Arduino IDE

When program the UNO development board, you can download the Arduino integrated development environment from the link:


See more contents at:


Ks0436-9.png

The functions of each button on the Toolbar are listed below:
IDE.png

IDE 1.png Verify/Compile Check the code for errors
IDE 2.png Upload Upload the current Sketch to the Arduino
IDE 3.png New Create a new blank Sketch
IDE 4.png Open Show a list of Sketches
IDE 5.png Save Save the current Sketch
IDE 6.png Serial Monitor Display the serial data being sent from the Arduino


Or you can browse the KEYESTUDIO website at this link, https://www.keyestudio.com/
Ks0446图片6.png



2)Introduction for Mixly Blocks

Mixly is a free open-source graphical Arduino programming software, based on Google’s Blockly graphical programming framework, and developed by Mixly Team@ BNU.
It is a free open-source graphical programming tool for creative electronic development; a complete support ecosystem for creative e-education; a stage for maker educators to realize their dreams.
More info please check the link to download the Mixly blocks software.

Before starting the robot projects, please click the link to get the basic understanding of Mixly software.
Ks0446图片8.png



3)Import Robot Library

For the robot kit, we have developed keyestudio frog robot library.
Don’t forget to import the keyestudio OTTO_Frog robot library to Mixly software before coding the robot projects.
Must import the robot library first, or else you can’t check all the test code.


Ks0446图片9.png

Unzip the OTTO_Frog library package, you can see the OTTO_Frog_Robot XML.document.
Ks0446图片10.png

Then import this document into Mixly library. Import custom library successfully!
Ks0446图片11.png

You are able to click “Manager” to manage all imported libraries.
Note: sometimes it may exists a conflict between libraries, so should keep only correct car library when using and delete other library.

Ks0446图片12.png



Hardware Projects

As you work your way through each project, you will learn to how to program the robot to move, dance, and follow obstacles.

Project 1: Keyestudio NANO CH340

Keyestudio Nano ch340


Introduction:
keyestudio Nano CH340 is a small, complete, and breadboard-friendly board based on the ATmega328P-AU. Compared with ARDUINO NANO, the USB-to-serial port chip used in keyestudio Nano is CH340G, so that the using method is the same except the driver installation file.
It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 8 analog inputs, a 16 MHz crystal oscillator, a mini USB port, an ICSP header and a reset button.
Note that ICSP (In-Circuit Serial Programming) header is used to program the firmware to ATMEGA328P-AU, but generally the chip has been preburned before leave the factory. So use it less.
The keyestudio Nano can be powered via the Mini-B USB connection, or female headers Vin/GND (DC 7-12V).


TECH SPECS:

Microcontroller ATmega328P-AU
Operating Voltage 5V
Input Voltage (recommended) DC7-12V
Digital I/O Pins 14 (D0-D13) (of which 6 provide PWM output)
PWM Digital I/O Pins 6 (D3, D5, D6, D9, D10, D11)
Analog Input Pins 8 (A0-A7)
DC Current per I/O Pin 40 mA
Flash Memory 32 KB of which 2 KB used by bootloader
SRAM 2 KB
EEPROM 1 KB
Clock Speed 16 MHz
LED_BUILTIN D13


Element and Interfaces:
Here is an explanation of what every element and interface of the board does:
Ks0173 pinout.jpg


Specialized Functions of Some Pins:

  • Serial communication: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data.
  • PWM (Pulse-Width Modulation): D3, D5, D6, D9, D10, D11
  • External Interrupts: D2 (interrupt 0) and D3 (interrupt 1). These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details.
  • SPI communication: D10 (SS), D11 (MOSI), D12 (MISO), D13 (SCK).
  • IIC communication: A4 (SDA); A5(SCL)


Project 2: keyestudio NANO Shield

Keyestudio NANO Shield (Black and Eco-friendly)


Introduction:
keyestudio Nano ch340 is a tiny control board based on Arduino platform, which is deeply popular.
However, if want to connect several sensor modules to keyestudio Nano ch340, and connect external power, we need to use breadboard and a bunch of jumper wires, which is pretty inconvenient.
We specially design this NANO shield, fully compatible with keyestudio Nano ch340.

TheNANO shield has brought out digital and analog pins of keyestudio Nano ch340 into 3PIN headers (GND, 5V, Signal) with pin pitch of 2.54mm.
The NANO shield also leads out frequently-used communication pins, such as serial port communication and I2C communication. It’s greatly easy to connect keyestudio Nano ch340 and other sensor modules.
It comes with a power indicator and a reset button as well.
For external power, the NANO shield comes with a PH2.0-2P connector (input DC7-12V); a Power_Switch for power control.
To supply power for other sensors, the NANO shield comes with a 3-way DC3.3V power output pin header with pin pitch of 2.54mm.
It comes with 4 fixing holes with a diameter of 3mm, so easy to mount on other devices.


Features:

  • 1.Extends 12 digital pins into 3pin header
  • 2.Extends 8 analog pins into 3pin header
  • 3.Comes with a serial communication pin header (for Bluetooth module)
  • 4.Comes with an I2C communication pin
  • 5.Comes with 3-way DC 3.3V power output pin
  • 6.Comes with a power indicator and a reset button
  • 7.Comes with an external power connector(PH2.0-2P)and a control button


thumb

Technical Parameters:

  • Voltage input: DC7-12V
  • Power connector: PH2.0-2P
  • Pin/Female header: 2.54mm
  • Fixing hole diameter: 3mm


Controller Compatible:


PINOUTS:

thumb


Use Method:
Simply stack the keyestudio Nano ch340 into the keystudio NANO shield. Supply the power with batteries via white connector.
thumb



Project 3: Adjusting Servo Angle

Servo


Introduction:
Servo motor is a position control rotary actuator. It mainly consists of housing, circuit board, core-less motor, gear and position sensor. 
Included with your servo motor you will find a variety of black mounts that connect to the shaft of your servo.
You may choose to attach any mount you wish for the circuit. It will serve as a visual aid, making it easier to see the servo spin.

Working principle:
The receiver or MCU outputs a signal to the servomotor. The motor has a built-in reference circuit that gives out reference signal, cycle of 20ms and width of 1.5ms. The motor compares the acquired DC bias voltage to the voltage of the potentiometer and outputs a voltage difference.

Servo motor comes with many specifications. But all of them have three connection wires, distinguished by brown, red, orange colors (different brand may have different color).
Brown one is for GND, red one for power positive, orange one for signal line.

thumb

The rotation angle of servo motor is controlled by regulating the duty cycle of PWM (Pulse-Width Modulation) signal. The standard cycle of PWM signal is 20ms (50Hz).
Theoretically, the width is distributed between 1ms-2ms, but in fact, it's between 0.5ms-2.5ms. The width corresponds the rotation angle from 0° to 180°.
But note that for different brand motor, the same signal may have different rotation angle. 

thumb


Connection Diagram:
Simply stack the keyestudio Nano ch340 into the keystudio NANO shield.
Connect the Servo pin to digital pin 4

thumb


Source Code:
We can set the HIGH/LOW for corresponding pins in the Mixly blocks software, so as to adjust the servo angle;
furthermore, we specially create the robot library, so easy to control the servo angle with simplified code.

thumb


Test Result:
Upload the Code success, press down the Power_Switch, the servo motor will rotate back and forth from 0°to 180°.


Little Knowledge:
1.Ks0446图片20.png this piece of block is used to direct regulate the servo. connect the servo signal pin to D4; set the servo angle to a variableKs0446图片21.png, that is, Ks0446图片22.png
This defined variable is applied to regulate the servo angle.
Because the servo angle is in the range of 0-180°, the range of variable Ks0446图片21.png should set from 0 to 180.
The delay period is in milliseconds, so if you want the LED display as fast, change the value 10.


Ks0446图片22.png
This block means variable i increases from 0 to 180, and each step increases 1.

Ks0446图片23.png
This block means variable i reduces from 180 to 0, and each step reduces 1.


Extension Practice:
1.Refer to the test code. Try to reset the servo pin and rotation speed
(Tips: set the delay time for servo angle ; or adjust to increase/reduce the step, which should be divisible by 180, like 2, 3, 5.)



Project 4: Ultrasonic Detecting Obstacles


Introduction:
The ultrasonic module will emit the ultrasonic waves after trigger signal. When the ultrasonic waves encounter the object and are reflected back, the module outputs an echo signal, so it can determine the distance of object from the time difference between trigger signal and echo signal.
We can use the ultrasonic sensor to detect whether there is an obstacle ahead. It is commonly used to measure the distance between the front obstacle and robot.
In the process of robot DIY, we can use the measured distance by ultrasonic sensor to build functional robots, such as automatic avoiding, following, etc.

In the experiment, we use the ultrasonic sensor to measure the distance between the robot and front obstacle.
The following picture is an ultrasonic module.
thumb

Specifications:

  • Operating voltage: DC 5V
  • Operating current: 15mA
  • Operating frequency: 40khz
  • Maximum detection range: 3-5m
  • Minimum detection range: 2cm
  • Induction Angle: less than 15 degrees
  • High accuracy: up to 3mm


Connection Diagram:
Connect the ultrasonic sensor to NANO shield, VCC pin to 5V(V), Trig pin to digital 6 (S), Echo pin to digital 7 (S), GND pin to GND(G); Then stack the NANO CH340 into the NANO shield.
thumb


Source Code:

thumb


Test Result:
Upload the code success, press the Power_Switch on NANO shield.
Open the monitor and set the baud rate to 9600.
Move your hand or a large, flat object closer and farther away from the ultrasonic sensor. As the object approaches, the monitor will show the distance (unit:cm) being read from the sensor.

thumb

thumb


Little Knowledge:
1.In the code, we use theKs0446图片29.png to measure the distance between ultrasonic sensor and obstacle ahead, with a unit of cm.
2.Ks0446图片30.png means the baud rate is set to 9600;
Ks0446图片31.png: print the distance value on the newline of monitor.

3.What happens when you change the number in the delay(200):Ks0446图片32.png
This delay period is in milliseconds, so if you want the LED display as low, change the value, try 2000.



Extension Practice:
1.You can add new texts or distance unit on the monitor display.
2.Change the baud rate and delay time to see the result.



Project 5: Bluetooth Module

keyestudio HM-10 Bluetooth-4.0 V3

Description:
Bluetooth technology is a wireless standard technology that enables short-distance data exchange between fixed devices, mobile devices, and building personal area networks (using UHF radio waves in the ISM band of 2.4 to 2.485 GHz).
The Keyestudio HM-10 Bluetooth-4.0 V3 module is a master-slave machine. When use as the Host, it can send commands to the slave actively; when use as the Slave, it can only receive commands from the host.
The HM-10 Bluetooth module supports the Bluetooth 4.0 protocol, which not only supports Android mobile, but also supports iOS system.


Technical Details:

  • 1)Bluetooth protocol: Bluetooth Specification V4.0 BLE
  • 2)No byte limit in serial port Transceiving
  • 3)In open environment, realize 100m ultra-distance communication with iphone4s
  • 4)USB protocol: USB V2.0
  • 5)Working frequency: 2.4GHz ISM band
  • 6)Modulation method: GFSK(Gaussian Frequency Shift Keying)
  • 7)Transmission power: -23dbm, -6dbm, 0dbm, 6dbm, can be modified by AT command.
  • 8)Sensitivity: ≤-84dBm at 0.1% BER
  • 9)Transmission rate: Asynchronous: 6K bytes ; Synchronous: 6k Bytes
  • 10)Security feature: Authentication and encryption
  • 11)Supporting service: Central & Peripheral UUID FFE0, FFE1
  • 12)Power consumption: Auto sleep mode, stand by current 400uA~800uA, 8.5mA during transmission.
  • 13)Power supply: 5V DC
  • 14)Working temperature: –5 to +65 Centigrade


thumb


Pins Description:

thumb


Wiring Diagram:

thumb


Test Code:
When uploading the code, CANNOT connect the Bluetooth module; otherwise uploading fails!
You are supposed to upload the code to control board, then connect the Bluetooth module.


thumb


Result:
First should install the APP on the cellphone. Download the APP from the link: https://wiki.keyestudio.com/KS0455_keyestudio_HM-10_Bluetooth-4.0_V3_Compatible_with_HC-06_Pins


  • For Android APP:

We only provide Android APP.
APP installed well, you can see the icon thumb on your Android phone.
After wiring, upload the test code to UNO R3 board and then connect the Bluetooth module. Powered on, Bluetooth module’s built in LED flashes.
Open the Android APPthumb, click to scan device. As shown below.
thumb

Click Scan Device to search the Bluetooth.
thumb

Click the first device thumb to connect the Bluetooth.
Connected, built-in LED on the Bluetooth module is normally on. APP interface will show the state connected.
thumb

On the bar enter letter a, and click to send, APP will print out the character “keyestudio” and D13 indicator on the UNO R3 board will flash once.
Continue to send the letter a, APP prints out multiple “keyestudio” character and D13 indicator flashes.
thumb


  • For mac/iOS APP

You need to download the mac/iOS compatible APP in APP store.
First we enter the APP store, search hm10, and select the hm10 bluetooth serial lite.
thumb


Click to install the APP, as shown below.
thumb


APP installed well, a Bluetooth iconthumb will pop up on your phone. Click to enter the APP.

Upload the test code to control board successfully, then plug in the Bluetooth module.
Open the Bluetooth APP, click thumb to start searching and pairing the Bluetooth module. Click thumbto start connecting HM-10 Bluetooth module.
Connected, the built-in LED on the Bluetooth module will be from quick flash to normally on.

thumb

On the input bar enter a letter a, and click to send, APP will print out the character “keyestudio” and D13 indicator on the UNO R3 board will flash once.
Continue to send the letter a, APP prints out multiple “keyestudio” characters and D13 indicator flashes.
thumb



Robot Projects

Let’s get started to assembling the lovely frog robot to move, dance or even follow objects. Do operate the robot easily with Bluetooth APP!
Follow this easy and simple instruction of how to install and program your Otto Frog Robot!
Ks0446图片34.png


ROBOT ASSEMBLY

All the parts for building frog robot are included in the kit, assembling them is easy and typically takes around two hours!

Note:
Before install the frog robot, first need to regulate the 4 servo motors to 90°

Stack the Nano ch340 onto the Nano shield; connect 4 servo motors to digital pin5,4,3,2 separately.
Ks0446图片35.png


Test Code:
Upload the code below to turn the 4 servos to 90°

Ks0446图片36.png


1)Fix Servo to Feet

Pay more attention to: avoiding wrong assembly
The foot Acrylic plate with groove should place on the top. Another acrylic plate with two big holes should place at the bottom.

  • Cut and attach 3 short pieces of dual-lock adhesive tape to the Acrylic frog feet. Each foot is combined with 2 piece of Acrylic plates.


Ks0446图片37.png


  • Then go to mount the 2 Servo motors on the 2 Acrylic plates with 4 M2*10MM round-head screws and 4 M2 nuts.


Ks0446图片38.png

  • Insert the 2 servo plates into frog feet.


Ks0446图片39.png


2)Fix Legs to Feet

  • Tighten the 2 Acrylic plates with a round-head screw M3*10MM, a M3 locknut and a Flange bearing.

Same process for other 2 Acrylic plates.

Ks0446图片40.png

  • Fix 2 Acrylic plates to foot acrylic plate with 4 round-head screws M3*10MM and 4 M3 nickel plating nuts.


Ks0446图片41.png

  • Fix another 2 Acrylic plates and black servo mount to Servo with servo accessories and 2 M1.2*5MM tapping screws.

(special note: the servo angle has been regulated to 90°, can’t change by hand)

Ks0446图片42.png

Ks0446图片43.png


3)Fix Servos to Body

  • First, fix four M3*30MM dual-pass copper pillars onto the Acrylic plate with four M3*6MM round-head screws.


Ks0446图片44.png

  • Then fix 2 Servos to the Acrylic plate with 4 M2*10MM round-head screws and 4 M2 nickel plating nuts.


Ks0446图片45.png

  • Then fix another 2 Acrylic plate and servo mount to the Servo with 4 servo screws.

(special note: the servo angle has been regulated to 90°)

Ks0446图片46.png

  • Fix the 2 servo mount screws shown as below:


Ks0446图片62.png


4)Fix Legs to Body

  • Fix the servo body to the legs with four M3*10MM flat-head screws and four nuts.


Ks0446图片47.png

  • Note here should rotate the frog leg to 90°, easy to fix the nuts and screws.


Ks0446图片48.png

Ks0446图片63.pngKs0446图片64.png

  • Same process for the other leg.


Ks0446图片49.png

Ks0446图片50.png

Ks0446图片51.pngKs0446图片52.png


5)Fix Head to Body

  • First should mount the 4 M3*10MM copper pillars on the top Acrylic plate with four M3*6MM round-head screws.


Ks0446图片53.png

  • Insert the HC-SR04 ultrasonic sensor into the Acrylic plate; tighten them with four M1.6*10MM round-head screws and four 1.6 nuts.


Ks0446图片54.png

  • Fix the frog head acrylic to top body acrylic plate with a M3*10MM flat-head screw and a M3 nickel plating nut.


Ks0446图片55.png

  • Fix the battery case to top body acrylic plate with two M3*10MM flat-head screws and two M3 nickel plating nuts.


Ks0446图片56.png

  • Fix the frog head onto the body acrylic parts with 4 M3*6MM round-head screws.


Ks0446图片57.png


6)Hookup Guide

  • First should mount the keyestudio NANO shield onto the top Acrylic plate with 4 M3*6MM round-head screws.


Ks0446图片58.png

  • Stack the Keyestudio nano ch340 control board onto keyestudio NANO shield.


Ks0446图片59.png


  • Connect the HC-SR04 ultrasonic sensor to keyestudio NANO shield using 4pin female to female jumper wires.

VCC pin to 5V(V), Trig pin to digital 6 (S), Echo pin to digital 7 (S), GND pin to GND(G);
(The ultrasonic sensor wiring can refer to the Project 4)

  • Connect 4 servo motors to digital pin5,4,3,2 separately.

(The 4 servos wiring can refer to the Project 3)

Ks0446图片60.png


  • The 4 servo motors’ wiring figure:
         ---------------
        |     O   O     |
        |---------------|
YR D3==> |             |   <== YL D2
         ---------------
            ||     ||
            ||     ||
RR D5==>  -----   ------   <== RL D4
         |-----   ------|


  • Plug in the Keyestudio HM-10 Bluetooth-4.0 module to pin header TX, RX, GND, 5V on the keyestudio NANO shield.


Ks0446图片61.png



Project 6: Walk

Ks0446图片65.png


Circuit Design:
After completing the robot assembly, you’ll see the 4 Servo motors on the robot are connected well to the keyestudio Nano ch340 shield.
We have introduced the knowledge of how to adjust the Servo angle.
In the circuit, we are going to make the 4 Servo motors switch different angles using keyestudio Nano ch340 shield, so as to operate the frog robot walk.

How it works?
When design the Otto frog robot, should first design the 4 Servo motors’ position and corresponding control pins.
Check the detailed instructions for servo control pins. As the figure shown below.


         ---------------
        |     O   O     |
        |---------------|
YR D3==> |             |   <== YL D2
         ---------------
            ||     ||
            ||     ||
RR D5==>  -----   ------   <== RL D4
         |-----   ------|


Hookup Guide:
Simply stack the keyestudio Nano ch340 into the keystudio NANO shield.
Connect the Servo pin to digital pin 2, 3, 4, 5 separately.


Error creating thumbnail: File with dimensions greater than 12.5 MP



Code:
Note: should upload the code success first, then plug in Bluetooth module. Otherwise, code upload fails.

Ks0446图片67.png


Result:
Done uploading the code, press down the Power_Switch on Nano Shield.
The Otto frog robot is ready to walk 5 steps forward, back 5 steps, keep standing for 1 second, turn left for 5 steps, turn right for 5 steps, keep standing for 1 second, alternately and loop.
Ks0446图片68.png

Ks0446图片61.png