Skip to content

Commit 7b7744f

Browse files
authored
Update AmebaD Example Guide (Ameba-AIoT#44)
* Update AmebaD Example Guide Update Example Guides for AMB21/23/AW-CU488 * Delete Play and Record Wav Files.rst
1 parent 01e778d commit 7b7744f

File tree

52 files changed

+2358
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2358
-4
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
AmebaMotor - Use Ameba as Server to Control Motors
2+
==================================================
3+
4+
.. contents::
5+
:local:
6+
:depth: 2
7+
8+
Introduction to AmebaMotors
9+
----------------------------
10+
11+
AmebaMotors is a library which provides API related to controlling motors.
12+
13+
Please download the library: AmebaMotors (https://github.com/Ameba-AIoT/ameba-arduino-d/blob/master/Arduino_zip_libraries/AmebaMotors.zip)
14+
15+
And add the library to Ameba: https://www.arduino.cc/en/Guide/Libraries#toc4
16+
17+
Materials
18+
---------
19+
20+
- AmebaD [AMB21 / AMB22 / AW-CU488 Thing Plus] x 1
21+
22+
- L298N H-Bridge x 1
23+
24+
- 4-wheel motorcar or 2-wheel motorcar + Universal wheel
25+
26+
Example
27+
-------
28+
29+
In this example, we connect Ameba to WiFi and use Ameba as server, the user can control a 4-wheel/2-wheel motorcar through a webpage.
30+
31+
First, connect Ameba to the L298N H-Bridge and the motorcar.
32+
33+
To know more about motor movement and the technical details of the L298N H-Bridge, please check out this link https://www.amebaiot.com/en/ameba-arduino-amebamotors-basic/.
34+
35+
Open the example, “Files” -> “Examples” -> “AmebaWiFi” -> “WiFiControlCar”.
36+
37+
You will see we use the following pins in the example:
38+
39+
Wiring:
40+
41+
|image01|
42+
43+
Note:
44+
45+
- We connect Ameba 5V to L298N +12V to supply power. However, not every L298N accepts 5V power supply, if this does not work, please connect L298N +12V to other power supply (e.g., +12V) and use L298N +5V to supply power to Ameba.
46+
47+
- The correct wiring of the motor depends on each model (may be opposite). Please run the test program first, make sure it runs correctly before assembling the motorcar.
48+
49+
- For convenience purposes, it's recommended to use Dupont line to organize the wiring of motors and L298N.
50+
51+
Every time you modify your program, please remember to unplug the power of L298N to avoid the motor running unexpectedly. Connect Ameba to power, upload the program, and then connect L298N to power when you are going to test the program.
52+
53+
Then, upload the code to Ameba
54+
55+
In the sample code, modify the highlighted snippet to corresponding information.
56+
57+
|image02|
58+
59+
Upload the code and press the reset button on Ameba. When the connection is established, you will see the message “To see this page in action, open a browser to http://xxx.xxx.xxx.xxx” in the Arduino IDE, as shown in the figure:
60+
61+
|image03|
62+
63+
Next, open the browser of a computer or a cell phone under the same WiFi domain, enter the address in the message.
64+
65+
|image04|
66+
67+
In the webpage, you can press the corresponding button to control the motor car in any of the 4 directions.
68+
69+
Demo Video
70+
-----------
71+
https://youtu.be/ItVaPQ4dv8Q
72+
73+
Code Reference
74+
---------------
75+
| Use WiFi.begin() to establish WiFi connection.
76+
| https://www.arduino.cc/en/Reference/WiFiBegin
77+
78+
| To get the information of a WiFi connection:
79+
80+
| Use WiFi.SSID() to get SSID of the current connected network.
81+
| https://www.arduino.cc/en/Reference/WiFiSSID
82+
83+
| Use WiFi.RSSI() to get the signal strength of the connection.
84+
| https://www.arduino.cc/en/Reference/WiFiRSSI
85+
86+
| Use WiFi.localIP() to get the IP address of Ameba.
87+
| https://www.arduino.cc/en/Reference/WiFiLocalIP
88+
89+
| Use WiFiServer server() to create a server that listens on the specified port.
90+
| https://www.arduino.cc/en/Reference/WiFiServer
91+
92+
| Use server.begin() to tell the server to begin listening for incoming connections.
93+
| https://www.arduino.cc/en/Reference/WiFiServerBegin
94+
95+
| Use server.available() to get a client that is connected to the server and has data available for reading.
96+
| https://www.arduino.cc/en/Reference/WiFiServerAvailable
97+
98+
| Use client.connected to get whether or not the client is connected.
99+
| https://www.arduino.cc/en/Reference/WiFiClientConnected
100+
101+
| Use client.println() to print data followed by a carriage return and newline.
102+
| https://www.arduino.cc/en/Reference/WiFiClientPrintln
103+
104+
| Use client.print() to print data to the server that a client is connected to.
105+
| https://www.arduino.cc/en/Reference/WiFiClientPrint
106+
107+
| Use client.available() to return the number of bytes available for reading.
108+
| https://www.arduino.cc/en/Reference/WiFiClientAvailable
109+
110+
| Use client.read() to read the next byte received from the server the client is connected to.
111+
| https://www.arduino.cc/en/Reference/WiFiClientRead
112+
113+
| Use client.stop() to disconnect from the server the client is connected to.
114+
| https://www.arduino.cc/en/Reference/WiFIClientStop
115+
116+
.. |image01| image:: ../../../../_static/amebad/Example_Guides/AmebaMotors/image01.png
117+
:width: 827 px
118+
:height: 709 px
119+
120+
.. |image02| image:: ../../../../_static/amebad/Example_Guides/AmebaMotors/image02.png
121+
:width: 795 px
122+
:height: 592 px
123+
124+
.. |image03| image:: ../../../../_static/amebad/Example_Guides/AmebaMotors/image03.png
125+
:width: 854 px
126+
:height: 431 px
127+
128+
.. |image04| image:: ../../../../_static/amebad/Example_Guides/AmebaMotors/image04.png
129+
:width: 714 px
130+
:height: 478 px
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
AmebaMotor
2+
===========
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
7+
AmebaMotor - Use Ameba as Server to Control Motors
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
AudioCodec - Basic Input Output
2+
================================
3+
4+
.. contents::
5+
:local:
6+
:depth: 2
7+
8+
Materials
9+
---------
10+
11+
- AmebaD [ AMB21 / AMB22 / AMB23 / AW-CU488 Thing Plus ] x 1
12+
13+
- Potentiometer x 1
14+
15+
- Analog microphone x 1 (e.g., Adafruit 1063 / 1064)
16+
17+
- 3.5mm TRS/TRRS breakout x 1 (e.g., Adafruit 2791 / Sparkfun 11570)
18+
19+
Example
20+
-------
21+
22+
Connect the potentiometer, microphone and 3.5mm connector to the RTL8722 board following the diagram.
23+
24+
|image01|
25+
26+
Open the example, “Files” -> “Examples” -> “AmebaAudioCodec” -> “BasicInputOutput”.
27+
28+
|image04|
29+
30+
Upload the code and press the reset button on Ameba once the upload is finished.
31+
32+
Connect a pair of wired headphones to the 3.5mm audio jack, blow at the microphone, and you should hear the sounds picked-up by the microphone replayed in the headphones. Adjust the potentiometer and the output volume will change as well. Note: if you are using a microphone with an amplifier included, such as Adafruit 1063, the amplifier can lead to the microphone picking up more noise.
33+
34+
.. |image01| image:: ../../../../_static/amebad/Example_Guides/AudioCodec/Audio_Codec_Basic_Input_Output/image01.png
35+
:width: 766 px
36+
:height: 638 px
37+
38+
.. |image04| image:: ../../../../_static/amebad/Example_Guides/AudioCodec/Audio_Codec_Basic_Input_Output/image04.png
39+
:width: 608 px
40+
:height: 830 px
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
AudioCodec - FFT
2+
=================
3+
4+
Materials
5+
---------
6+
7+
- AmebaD [ AMB21 / AMB22 / AMB23 / AW-CU488 Thing Plus ] x 1
8+
9+
Example
10+
-------
11+
12+
This example shows how to use the FFT class to calculate the fast Fourier transform of a signal to extract the frequencies present in the signal.
13+
14+
Open the example, “Files” -> “Examples” -> “AmebaAudioCodec” -> “FFT”.
15+
16+
|image01|
17+
18+
Upload the code and press the reset button on Ameba once the upload is finished.
19+
20+
Open the serial monitor, and the output results of the FFT calculation will be displayed.
21+
22+
|image02|
23+
24+
.. |image01| image:: ../../../../_static/amebad/Example_Guides/AudioCodec/Audio_Codec_FFT/image01.png
25+
:width: 608 px
26+
:height: 830 px
27+
28+
.. |image02| image:: ../../../../_static/amebad/Example_Guides/AudioCodec/Audio_Codec_FFT/image02.png
29+
:width: 639 px
30+
:height: 477 px
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
AudioCodec - Input FFT
2+
=======================
3+
4+
Materials
5+
---------
6+
7+
- AmebaD [ AMB21 / AMB22 / AMB23 / AW-CU488 Thing Plus ] x 1
8+
9+
- Analog microphone x 1 (e.g., Adafruit 1063 / 1064) x 1
10+
11+
Example
12+
-------
13+
14+
This example shows how to use the FFT class to calculate the fast Fourier transform of the audio signal recorded by the microphone.
15+
16+
Connect the microphone to the RTL8722 board following the diagram.
17+
18+
|image01|
19+
20+
Next, Open the example, “Files” -> “Examples” -> “AmebaAudioCodec” -> “InputFFT”.
21+
22+
|image03|
23+
24+
Upload the code and press the reset button on Ameba once the upload is finished.
25+
26+
Open the serial monitor and change the baud rate to 2000000. A stream of FFT results of audio samples will be displayed. Try playing music or use a smartphone app to generate a sine wave into the microphone, and you should be able to see the FFT output change.
27+
28+
|image04|
29+
30+
.. |image01| image:: ../../../../_static/amebad/Example_Guides/AudioCodec/Audio_Codec_InputFFT/image01.png
31+
:width: 628 px
32+
:height: 627 px
33+
34+
.. |image03| image:: ../../../../_static/amebad/Example_Guides/AudioCodec/Audio_Codec_InputFFT/image03.png
35+
:width: 608 px
36+
:height: 830 px
37+
38+
.. |image04| image:: ../../../../_static/amebad/Example_Guides/AudioCodec/Audio_Codec_InputFFT/image04.png
39+
:width: 1206 px
40+
:height: 578 px
41+
:scale: 70%
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
AudioCodec - Output Sine Wave
2+
==============================
3+
4+
Materials
5+
---------
6+
7+
- AmebaD [ AMB21 / AMB22 / AMB23 / AW-CU488 Thing Plus ] x 1
8+
9+
- 3.5mm TRS/TRRS breakout x 1 (e.g., Adafruit 2791 / Sparkfun 11570) x 1
10+
11+
Example
12+
-------
13+
14+
Connect the 3.5mm connector to the RTL8722 board following the diagram.
15+
16+
|image01|
17+
18+
Open the example, “Files” -> “Examples” -> “AmebaAudioCodec” -> “OutputSineWave”.
19+
20+
|image03|
21+
22+
Upload the code and press the reset button on Ameba once the upload is finished.
23+
24+
Connect a pair of wired headphones to the 3.5mm audio jack and you should hear the generate single sinusoidal tone.
25+
26+
.. |image01| image:: ../../../../_static/amebad/Example_Guides/AudioCodec/Audio_Codec_Output_Sine_Wave/image01.png
27+
:width: 648 px
28+
:height: 625 px
29+
30+
.. |image03| image:: ../../../../_static/amebad/Example_Guides/AudioCodec/Audio_Codec_Output_Sine_Wave/image03.png
31+
:width: 608 px
32+
:height: 830 px
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
AudioCodec
2+
===========
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
7+
AudioCodec - Basic Input Output
8+
AudioCodec - FFT
9+
AudioCodec - Input FFT
10+
AudioCodec - Output Sine Wave

0 commit comments

Comments
 (0)