diff --git a/bak/Example_Guides/GPIO - Interrupt Control LED/GPIO - Interrupt Control LED.rst b/bak/Example_Guides/GPIO - Interrupt Control LED/GPIO - Interrupt Control LED.rst deleted file mode 100644 index ea8eb20..0000000 --- a/bak/Example_Guides/GPIO - Interrupt Control LED/GPIO - Interrupt Control LED.rst +++ /dev/null @@ -1,81 +0,0 @@ -Preparation - -- AmebaPro2 [AMB82 MINI] x 1 - -- Button x 1 - -Example - -In this example, we use a button to trigger interrupt and control the -LED. - -When we press and release the button, the LED dims, press and release -the button again, and the LED lights up. Note that in the Arduino -example “Button and LED”, LED only lights up when the button is pressed -and hold, when we release the button, the LED dims. - -Open the example, “File” -> “Examples” -> “AmebaGPIO” -> -“Interrupt_Ctrl_LED” - -|Graphical user interface, application Description automatically -generated| - -Since there is no in-built push button on AmebaPro2 [AMB82 MINI], you -may choose to change the code highlighted in yellow to any GPIO pin -number. In this example, GPIO pin 0 is used. - -|Graphical user interface, text, application Description automatically -generated| - -**AMB82 MINI wiring** **diagram:** - -|image1| - -| Compile and upload the program, press the reset button on the Ameba. -| The LED will light up at first. Press and release the button, then the - LED should dim. Press the button again the LED should light up. - -Code Reference - -In - -setup() - -we set the GPIO pin in the above example to - -INPUT_IRQ_RISE - -, this means that an interrupt occurs when the voltage of this pin -changes from GND to 3V3. Therefore, we connect the other side of the -button to 3V3, so as to trigger interrupt event when the button is -pressed. - -pinMode(button, INPUT_IRQ_RISE); - -On the other hand, we can set the GPIO pin in the above example to - -INPUT_IRQ_FALL - -, this means that an interrupt occurs when the voltage of this pin -changes from 3V3 to GND. In this case, the other side of the button is -connected to GND. Next, we need to specify the function to be executed -to handle the interrupt: - -digitalSetIrqHandler(button, button_handler); - -The second parameter is a function pointer, with prototype: - -void button_handler(uint32_t id, uint32_t event) - -In this handler, every time we press and release the button, we trigger -an interrupt, and change the status of the LED. - -.. |Graphical user interface, application Description automatically generated| image:: ../../_static/Example_Guides/GPIO_-_Interrupt_Control_LED/GPIO_-_Interrupt_Control_LED_images/image01.png - :width: 3.79463in - :height: 4.5417in -.. |Graphical user interface, text, application Description automatically generated| image:: ../../_static/Example_Guides/GPIO_-_Interrupt_Control_LED/GPIO_-_Interrupt_Control_LED_images/image02.png - :width: 3.12755in - :height: 3.82992in -.. |image1| image:: ../../_static/Example_Guides/GPIO_-_Interrupt_Control_LED/GPIO_-_Interrupt_Control_LED_images/image03.png - :width: 6.25556in - :height: 2.971in diff --git a/bak/Example_Guides/GPIO - Interrupt Control LED/GPIO - Measure Distance by HCSR04 Ultrasonic.rst b/bak/Example_Guides/GPIO - Interrupt Control LED/GPIO - Measure Distance by HCSR04 Ultrasonic.rst deleted file mode 100644 index a0e9f61..0000000 --- a/bak/Example_Guides/GPIO - Interrupt Control LED/GPIO - Measure Distance by HCSR04 Ultrasonic.rst +++ /dev/null @@ -1,94 +0,0 @@ -Preparation - -- AmebaPro2 [AMB82 MINI] x 1 - -- HC-SR04 Ultrasonic x 1 - -- Dropping resistor or Level converter - -Example - -| HC-SR04 is a module that uses ultrasound to measure the distance. It - looks like a pair of eyes in its appearance; therefore, it’s often - installed onto robot-vehicle or mechanical bugs to be their eyes. -| The way it works is that first we “toggle high” the TRIG pin (that is - to pull high then pull low). The HC-SR04 would send eight 40kHz sound - wave signal and pull high the ECHO pin. When the sound wave returns, - it pulls low the ECHO pin. - -|1| - -Assume the velocity of sound is 340 m/s, the time it takes for the sound -to advance 1 cm in the air is 340*100*10^-6 = 29 us. - -| The sound wave travels twice the distance between HC-SR04 and the - object, therefore the distance can be calculated by (time/29) / 2 = - time / 58. -| The working voltage of HC-SR04 is 5V. When we pull high the ECHO pin - to 5V, the voltage might cause damage to the GPIO pin of Ameba. To - avoid this situation, we need to drop the voltage as follows: - -**AMB82 MINI** Wiring Diagram: - -|image1| - -| We pick the resistors with resistance 1:2, any value of resistance is - fine but not recommended too high values. -| If you do not have resistors in hand, you can use level converter - instead. The TXB0108 8 channel level converter is a suitable example: - -**AMB82 MINI** Wiring Diagram: - -|image2| - -Next, open the sample code in “File” -> “Examples” -> “AmebaGPIO” -> -“HCSR04_Ultrasonic” - -|image3| - -Compile and upload to Ameba, then press the reset button. Open the -Serial Monitor, the calculated result is output to serial monitor every -2 seconds. - -|4| - -Note that the HCSR04 module uses the reflection of sound wave to -calculate the distance, thus the result can be affected by the surface -material of the object (e.g., harsh surface tends to cause scattering of -sound wave, and soft surface may cause the sound wave to be absorbed). - -Code Reference - -Before the measurement starts, we need to pull high the TRIG pin for -10us and then pull low. By doing this, we are telling the HC-SR04 that -we are about to start the measurement: - -digitalWrite(trigger_pin, HIGH); - -delayMicroseconds(10); - -digitalWrite(trigger_pin, LOW); - -Next, use pulseIn to measure the time when the ECHO pin is pulled high. - -duration = pulseIn (echo_pin, HIGH); - -Finally, use the formula to calculate the distance. - -distance = duration / 58; - -.. |1| image:: ../../_static/Example_Guides/GPIO_-_Measure_Distance_HCSR04_Ultrasonic/GPIO_-_Measure_Distance_by_HCSR04_Ultrasonic_images/image01.png - :width: 5.264in - :height: 3.24028in -.. |image1| image:: ../../_static/Example_Guides/GPIO_-_Measure_Distance_HCSR04_Ultrasonic/GPIO_-_Measure_Distance_by_HCSR04_Ultrasonic_images/image02.png - :width: 6.26806in - :height: 3.82234in -.. |image2| image:: ../../_static/Example_Guides/GPIO_-_Measure_Distance_HCSR04_Ultrasonic/GPIO_-_Measure_Distance_by_HCSR04_Ultrasonic_images/image03.png - :width: 6.26806in - :height: 3.79882in -.. |image3| image:: ../../_static/Example_Guides/GPIO_-_Measure_Distance_HCSR04_Ultrasonic/GPIO_-_Measure_Distance_by_HCSR04_Ultrasonic_images/image04.png - :width: 3.54258in - :height: 4.99791in -.. |4| image:: ../../_static/Example_Guides/GPIO_-_Measure_Distance_HCSR04_Ultrasonic/GPIO_-_Measure_Distance_by_HCSR04_Ultrasonic_images/image05.png - :width: 6.26806in - :height: 3.59028in diff --git a/bak/Example_Guides/GPIO - Interrupt Control LED/GPIO - Measure Temperature and Humidity DHT Tester.rst b/bak/Example_Guides/GPIO - Interrupt Control LED/GPIO - Measure Temperature and Humidity DHT Tester.rst deleted file mode 100644 index f1c62e9..0000000 --- a/bak/Example_Guides/GPIO - Interrupt Control LED/GPIO - Measure Temperature and Humidity DHT Tester.rst +++ /dev/null @@ -1,89 +0,0 @@ -Preparation - -- AmebaPro2 [AMB82 MINI] x 1 - -- DHT11 or DHT22 or DHT21 - -Example - -| DHT11 is a temperature and humidity sensor which operates at voltage - 3.3V~5V. At room temperature, the measurable range of the humidity is - 20% ~ 90%RH with ±5%RH precision, the measurable range of the - temperature is 0 ~ 50℃ with ±2℃ precision. -| Another choice of temperature and humidity sensor is DHT22 sensor, - which has better precision. Its measurable range of the humidity is - 0%~100%RH with ±5%RH precision, the measurable range of the - temperature is -40~125 ℃ with ±0.2℃ precision. -| There are 4 pins on the sensor: - -|1| - -Since one of the 4 pins has no function, there are temperature/humidity -sensors with only 3 pins on the market: - -|2| - -DHT is normally in the sleeping mode. To get the temperature/humidity -data, please follow the steps: - -1. Awake DHT: Ameba toggles low its DATA pin of GPIO. Now the DATA pin - of GPIO serves as digital out to Ameba. - -2. DHT response: DHT also toggle low its DATA pin of GPIO. Now the DATA - pin of GPIO serves as digital in for Ameba. - -3. DHT sends data: DHT sends out the temperature/humidity data (which - has size 5 bytes) in a bit-by-bit manner. To represent each bit, DHT - first pull low the DATA GPIO pin for a while and then pull high. If - the duration of high is smaller than low, it stands for bit 0. - Otherwise, it stands for bit 1. - -|3| - -Take note that if you are using a DHT sensor that is not mounted on a -PCB, you will have to add in a 10K Ohm pull up resistor. You may refer -to the wiring diagrams. - -| **AMB82 wiring diagram:** -| *DHT sensor not mounted on a PCB* *board* - -|image1| - -*DHT sensor mounted on a PCB* *board* - -|image2| - -Open the sample code in “Files” -> “Examples” -> “AmebaGPIO” -> -“DHT_Tester”. Compile and upload to Ameba, then press the reset button. -The result would be shown on the Serial Monitor. - -|image3| - -Code Reference - -Use dht.readHumidity() read the humidity value, and -use dht.readTemperature() to read the temperature value. - -Every time we read the temperature/humidity data, Ameba uses the -buffered temperature/humidity data unless it found the data has expired -(i.e., has not been updated for over 2 seconds). If the data is expired, -Ameba issues a request to DHT to read the latest data. - -.. |1| image:: ../../_static/Example_Guides/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester_images/image01.png - :width: 1.9913in - :height: 2.55564in -.. |2| image:: ../../_static/Example_Guides/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester_images/image02.png - :width: 0.70788in - :height: 1.71304in -.. |3| image:: ../../_static/Example_Guides/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester_images/image03.png - :width: 6.26806in - :height: 1.81944in -.. |image1| image:: ../../_static/Example_Guides/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester_images/image04.png - :width: 5.30057in - :height: 2.65555in -.. |image2| image:: ../../_static/Example_Guides/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester_images/image05.png - :width: 3.67919in - :height: 3.00058in -.. |image3| image:: ../../_static/Example_Guides/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester/GPIO_-_Measure_Temperature_and_Humidity_DHT_Tester_images/image06.png - :width: 4.7013in - :height: 3.94514in diff --git a/bak/Example_Guides/GTimer - Timer Oneshot/GTimer - Timer Oneshot.rst b/bak/Example_Guides/GTimer - Timer Oneshot/GTimer - Timer Oneshot.rst deleted file mode 100644 index fa088dc..0000000 --- a/bak/Example_Guides/GTimer - Timer Oneshot/GTimer - Timer Oneshot.rst +++ /dev/null @@ -1,35 +0,0 @@ -Preparation - -- AmebaPro2 [AMB82 MINI] x 1 - -Example - -In this example, we will use 4 One-Time GTimer, and pass user data to -each timer. - -Open the example “File” -> “Examples” -> “AmebaGTimer” -> -“TimerOneshot”. Compile and upload to Ameba, and press reset. Then you -can see the 4 timer log printed to the serial monitor in series. - -Code Reference - -| The first argument of begin() is the Timer ID (0~3). The second - argument is the value of the timer (in microseconds). -| In the example, we fill in 1000000us = 1s. The third argument - specifies the function to call when the time is up. -| The fourth argument is to set whether this timer is a periodic timer, - we use “false” here to begin a single-use timer. -| The fifth argument is the user data, we give 0 here to represent that - this is timer 0. - -GTimer.begin(0, 1 \* 1000 \* 1000, myhandler, false, 0); - -Next, we set up the second timer, which has timer value 2 seconds, and -user data 1. And other timers are set similarly. - -GTimer.begin(1, 2 \* 1000 \* 1000, myhandler, false, 1); - -In myhandler function, we print the user data to serial monitor. Since -the 4 timers are separately set to count for 1, 2, 3, 4 seconds, from 1 -second to 4 second, the user data of each timer are printed on the -serial monitor in order. After 4 second, no log will be printed. diff --git a/bak/Example_Guides/GTimer - Timer Oneshot/GTimer - Timer Periodical.rst b/bak/Example_Guides/GTimer - Timer Oneshot/GTimer - Timer Periodical.rst deleted file mode 100644 index 65a5f3d..0000000 --- a/bak/Example_Guides/GTimer - Timer Oneshot/GTimer - Timer Periodical.rst +++ /dev/null @@ -1,34 +0,0 @@ -Preparation - -- AmebaPro2 [AMB82 MINI] x1 - -Example - -Ameba provides 4 hardware GTimer for users to use. The timers’ -resolutions are at microseconds scale. - -The timer can be set to be periodic or for single use. The periodic -timers reset periodically, and the single-use timers do not. - -Open the example, “File” -> “Examples” -> “AmebaGTimer” -> -“TimerPeriodical”. Compile and upload to Ameba, and press reset. - -In the Serial Monitor, you can see the counter value is increased -periodically. - -Code Reference - -| The first argument of begin() is the timer id (0~3). -| The second argument is the value of the timer (in microseconds). In - the example, we fill in 1000000us = 1s. -| The third argument specifies the function to call when the time is up. - In the example, we call the “myhandler” function to increase the - counter value by 1 and print the counter value to serial monitor. - -GTimer.begin(0, 1 \* 1000 \* 1000, myhandler); - -| The GTimer is periodic by default, therefore “myhandler” function is - called every second. -| When we want to stop the GTimer, use “stop()”: - -GTimer.stop(0); diff --git a/bak/Example_Guides/MQTT - Set up Client/MQTT - Set up Client TLS.rst b/bak/Example_Guides/MQTT - Set up Client/MQTT - Set up Client TLS.rst deleted file mode 100644 index 5bc0f4d..0000000 --- a/bak/Example_Guides/MQTT - Set up Client/MQTT - Set up Client TLS.rst +++ /dev/null @@ -1,67 +0,0 @@ -Preparation - -- AmebaPro2 [AMB82 MINI] x 1 - -Example - -In this example, Ameba connect to a MQTT broker using TLS -authentication. Then send messages as a publisher and receive messages -as a subscriber. - -Open example at “File” -> “Examples” -> “AmebaMQTTClient” -> “MQTT_TLS” - -Please modify the WiFi-related parameters and MQTT parameters. - -|A picture containing text, screenshot, font Description automatically -generated| - -- “ssid” is the network SSID for internet access. - -- “pass” is the network password for internet access. - -- The “mqttServer” refers to the MQTT-Broker, there is free MQTT - sandbox “test.mosquitto.org” for testing. - -- “clientId” is an identifier for MQTT-Broker to identify the connected - device. - -- “publishTopic” is the topic of the published message. It is - “outTopic” in the example. The devices that subscribed to “outTopic” - will receive the message. - -- “publishPayload” is the content to be published. - -- “subscribeTopic” is to tell MQTT-broker which topic to subscribe to - by the board. - -Next, compile the code and upload it to Ameba. Press the reset button, -then open the serial monitor. - -|image1| - -After Ameba is connected to MQTT server, it sends the message “hello -world” to “outTopic”. To see the message, use another MQTT client. Refer -to the MQTT_Basic example guide on how to setup a PC-based MQTT client. - -In addition to use TLS client authentication to server authentication, -it requires to generate an OpenSSL private key and obtain a signed -certificate from the server. For testing purposes, signed certificates -can be obtained from test.mosquitto.org by following the guide -at https://test.mosquitto.org/ssl/. - -Replace the character strings “certificateBuff” and “privateKeyBuff” -with the signed certificate and OpenSSL private key, ensuring that they -are formatted the same way as the shown in the example code. Set -“MQTT_TLS_SERVER_AUTH” to be “1”. - -|image2| - -.. |A picture containing text, screenshot, font Description automatically generated| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client_TLS/MQTT_-_Set_up_Client_TLS_images/image01.png - :width: 5.40625in - :height: 2.5in -.. |image1| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client_TLS/MQTT_-_Set_up_Client_TLS_images/image02.png - :width: 6.26806in - :height: 3.61528in -.. |image2| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client_TLS/MQTT_-_Set_up_Client_TLS_images/image03.png - :width: 2.66667in - :height: 0.53125in diff --git a/bak/Example_Guides/MQTT - Set up Client/MQTT - Set up Client.rst b/bak/Example_Guides/MQTT - Set up Client/MQTT - Set up Client.rst deleted file mode 100644 index cd87864..0000000 --- a/bak/Example_Guides/MQTT - Set up Client/MQTT - Set up Client.rst +++ /dev/null @@ -1,235 +0,0 @@ -Materials -========= - -- AmebaPro2 [AMB82 MINI] x 1 - -| Example -| **Introduction** - -| MQTT (Message Queuing Telemetry Transport) is a protocol proposed by - IBM and Eurotech. The introduction in `MQTT Official - Website `__: -| MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity - protocol. It was designed as an extremely lightweight - publish/subscribe messaging transport. We can say MQTT is a protocol - designed for IoT. MQTT is based on TCP/IP and transmits/receives data - via publish/subscribe. - -Please refer to the figure below: - -|9-1| - -In the operation of MQTT, there are several roles: - -- Publisher: Usually publishers are the devices equipped with sensors - (ex. Ameba). Publishers uploads the data of the sensors to - MQTT-Broker, which serves as a database with MQTT service. - -- Subscriber: Subscribers are referred to the devices which receive and - observe messages, such as a laptop or a mobile phone. - -- Topic: Topic is used to categorize the messages, for example the - topic of a message can be “PM2.5” or “Temperature”. Subscribers can - choose messages of which topics they want to receive. - -In this page, there are 3 examples that connect Ameba to MQTT-Broker. -Then send messages as publisher and receive messages from MQTT-Broker as -subscriber. - -1. MQTT_Basic - -2. MQTT_Auth - -3. MQTT_Publish_In_Callback - -| **Procedure** -| **MQTT_Basic example** - -Open the MQTT example “File” -> “Examples” -> “AmebaMQTTClient” -> -“MQTT_Basic” - -Please modify some WiFi-related parameter and some information related -to MQTT: - -|A screen shot of a computer code Description automatically generated -with low confidence| - -- “ssid” is the network SSID for internet access. - -- “pass” is the network password for internet access. - -- “mqttServer” refers to the MQTT-Broker, there is free MQTT sandbox - “test.mosquitto.org” for testing. - -- “clientId” is an identifier for MQTT-Broker to identify the connected - device. - -- “publishTopic” is the topic of the published message in the example - it is “outTopic”. The devices that subscribed to “outTopic” will - receive the message. - -- “publishPayload” is the content to be published. - -- “subscribeTopic” is to tell MQTT-broker which topic to subscribe to - by the board. - -Next, compile the code and upload it to Ameba. Press the reset button, -then open the serial monitor. - -|image1| - -After Ameba is connected to MQTT server, it sends the message “hello -world” to “outTopic”. To see the message, another MQTT client needs to -be set up. - -The “MQTT Explore” is an all-platform application that can be set as the -MQTT client. Refer to the website http://mqtt-explorer.com/. - -Click “Connections” at top left to start a new connection setup. “Name” -can be customized. Set “Host” as “test.mosquitto.org”. - -|A screenshot of a computer Description automatically generated| - -Click “ADVANCED” at bottom for topic setup. Use “outTopic” that same as -“publishTopic” of the board. Click “ADD” then “BACK”. - -|image2| - -Click “CONNECT”. The “hello world” message show up at left side. At -right side, under “Publish” use “inTopic” same as “sucribeTopic” of the -board. Choose “raw” and input “Text hello Ameba”, then click “PUBLISH”. -The board will receive the MQTT Explorer published raw message. Note, -because of the host is a free public host, the board may receive -unexpected messages. - -|image3| - -|image4| - -**MQTT_Auth example** - -Open the MQTT example “File” -> “Examples” -> “AmebaMQTTClient” -> -“MQTT_Auth” - -Please modify some WiFi-related parameter and some information related -to MQTT: - -|A screen shot of a computer program Description automatically generated -with low confidence| - -- “mqttServer” refers to the MQTT-Broker, there is free MQTT auth host - provided by amebaiot homepage “cloud.amebaiot.com”. Please visit - https://www.amebaiot.com/en/cloud-getting-started/ for account setup. - -- “clientId” is an identifier for MQTT-Broker to identify the connected - device. In this case, it is the registered device name. Refer to - https://www.amebaiot.com/en/cloud-service/. - -- “clientUser” is the authentication username. In this case, it is the - login username of Realtek IoT/Wi-Fi MCU Solutions website. Note, it - will be unable to receive message if use the email as “clientUser”. - -- “clientPass” is the authentication password. In this case, it is the - login password of Realtek IoT/Wi-Fi MCU Solutions website. - -- The other parameters are same as pervious. - -Next, compile the code and upload it to Ameba. Press the reset button, -then open the serial monitor. After Ameba is connected to MQTT server, -it sends the message “hello world” to “outTopic”. To see the message, -another MQTT client needs to be set up. - -Start the MQTT Explore, and setup the auth connection. - -Click “Connections” at top left to start a new connection setup. “Name” -can be customized. Set “Host” as “cloud. amebaiot.com”. “Username” and -“Password” are same as “clientUser” and “clientPass”. - -|image5| - -Click “ADVANCED” at bottom for topic setup. Use “outTopic” that same as -“publishTopic” of the board. Click “ADD” then “BACK”. - -Click “CONNECT”. The “hello world” message show up at left side. At -right side, under “Publish” use “inTopic” same as “sucribeTopic” of the -board. Choose “raw” and input “Text hello Ameba”, then click “PUBLISH”. -The board will receive the MQTT Explorer published raw message. Note, -“hello world” sometimes is not shown up because the boards connect to -MQTT broker before the MQTT Explorer. - -|image6| - -|image7| - -**MQTT_Publish_In_Callback example** - -Open the MQTT example “File” -> “Examples” -> “AmebaMQTTClient” -> -“MQTT_Publish_In_Callback” - -Please modify some WiFi-related parameter and some information related -to MQTT: - -- All parameters are same as MQTT_Auth example. - -Next, compile the code and upload it to Ameba. Press the reset button, -then open the serial monitor. After Ameba is connected to MQTT server, -it sends the message “hello world” to “outTopic”. To see the message, -another MQTT client needs to be set up. - -Start the MQTT Explore, and setup the auth connection. All setting is -same as MQTT_Auth example. - -Click “ADVANCED” at bottom for topic setup. Use “outTopic” that same as -“publishTopic” of the board. Click “ADD” then “BACK”. - -Click “CONNECT”. The “hello world” message show up at left side. At -right side, under “Publish” use “inTopic” same as “sucribeTopic” of the -board. Choose “raw” and input “Text hello Ameba”, then click “PUBLISH”. -The board will receive the MQTT Explorer published raw message. Then -publish it from the board side and MQTT Explorer will receive at the -left side. Note, “hello world” sometimes is not shown up because the -boards connect to MQTT broker before the MQTT Explorer. - -|image8| - -|image9| - -.. |9-1| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image01.png - :width: 6.26806in - :height: 4.11389in -.. |A screen shot of a computer code Description automatically generated with low confidence| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image02.png - :width: 5.1875in - :height: 1.89583in -.. |image1| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image03.png - :width: 6.26042in - :height: 4.14583in -.. |A screenshot of a computer Description automatically generated| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image04.png - :width: 6.25in - :height: 4.07919in -.. |image2| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image05.png - :width: 6.26806in - :height: 4.12222in -.. |image3| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image06.png - :width: 6.26806in - :height: 4.10556in -.. |image4| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image07.png - :width: 4.67708in - :height: 1.47917in -.. |A screen shot of a computer program Description automatically generated with low confidence| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image08.png - :width: 5.45833in - :height: 2.26042in -.. |image5| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image09.png - :width: 6.26806in - :height: 4.09514in -.. |image6| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image10.png - :width: 6.26806in - :height: 4.19306in -.. |image7| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image11.png - :width: 5.60417in - :height: 1.61458in -.. |image8| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image12.png - :width: 6.26806in - :height: 4.08889in -.. |image9| image:: ../../_static/Example_Guides/MQTT_-_Set_up_Client/MQTT_-_Set_up_Client_images/image13.png - :width: 5.70833in - :height: 1.57292in diff --git a/bak/Example_Guides/NTP - Retrieve Universal Time (UTC) by NTPClient library/NTP - Retrieve Universal Time (UTC) by NTPClient library.rst b/bak/Example_Guides/NTP - Retrieve Universal Time (UTC) by NTPClient library/NTP - Retrieve Universal Time (UTC) by NTPClient library.rst deleted file mode 100644 index 015ce97..0000000 --- a/bak/Example_Guides/NTP - Retrieve Universal Time (UTC) by NTPClient library/NTP - Retrieve Universal Time (UTC) by NTPClient library.rst +++ /dev/null @@ -1,66 +0,0 @@ -Preparation - -- AmebaPro2 [`AMB82 - Mini `__] - x 1 - -Example - -In this example, we use an NTP client to sync with NTP servers using UDP -and keep track of time locally.Open the example. “File” -> “Examples” -> -“NTPClient” -> “Advanced” - -|image1|\ Modify the highlighted code section (ssid, password) to -connect to your WiFi network. - -|image2| - -Compile the code and upload it to Ameba. After pressing the Reset -button, Ameba connects to WiFi, gets the UTC time from the NTP server, -and prints out the current time with time zone offset to the serial -monitor. - -|image3| - -Code Reference - -| Configure NTP client: -| The NTPClient needs to use a UDP client for communications. A WiFiUDP - client is declared and passed to the NTPClient constructor, along with - an NTP server address, time zone offset in seconds, and update - interval in milliseconds. If detailed configuration is not needed, - just passing in the UDP client is also sufficient, refer to the - “NTPClient” -> “Basic” example. - -WiFiUDP ntpUDP; - -NTPClient timeClient(ntpUDP, “europe.pool.ntp.org”, 3600, 60000); - -| Start NTP client: -| After connecting to WiFi, the NTPClient is started using the begin() - function, which causes the client to sync with the NTP server and get - the UTC time. - -WiFiUDP ntpUDP; - -timeClient.begin(); - -| Get local time: -| getFormattedTime() is used to format the received UTC time into the - local time zone. -| update() is called every loop so that the NTPClient will sync with the - NTP server once every update interval. - -timeClient.update(); - -timeClient.getFormattedTime(); - -.. |image1| image:: ../../_static/Example_Guides/NTP_-_Retrieve_Universal_Time_(UTC)_by_NTPClient_library/NTP_-_Retrieve_Universal_Time_(UTC)_by_NTPClient_library_images/image01.png - :width: 6.26806in - :height: 3.32222in -.. |image2| image:: ../../_static/Example_Guides/NTP_-_Retrieve_Universal_Time_(UTC)_by_NTPClient_library/NTP_-_Retrieve_Universal_Time_(UTC)_by_NTPClient_library_images/image02.png - :width: 3.76042in - :height: 3.88056in -.. |image3| image:: ../../_static/Example_Guides/NTP_-_Retrieve_Universal_Time_(UTC)_by_NTPClient_library/NTP_-_Retrieve_Universal_Time_(UTC)_by_NTPClient_library_images/image03.png - :width: 6.26806in - :height: 6.57083in diff --git a/bak/Example_Guides/PWM - Buzzer Play Melody/PWM - Buzzer Play Melody.rst b/bak/Example_Guides/PWM - Buzzer Play Melody/PWM - Buzzer Play Melody.rst deleted file mode 100644 index 713f6a1..0000000 --- a/bak/Example_Guides/PWM - Buzzer Play Melody/PWM - Buzzer Play Melody.rst +++ /dev/null @@ -1,50 +0,0 @@ -Preparation - -- AmebaPro2 [AMB82 MINI] x 1 - -- Buzzer x 1 - -Example - -A sound is composed of volume, tone and timbre. Volume is determined by -the amplitude of the sound wave. Tone is determined by the frequency of -the sound wave. Timbre is determined by the waveform of the sound wave. - -In this example, we use PWM to control the buzzer to emit sound with -desired tone. As PWM outputs square wave, if we wish to emit tone C4 -(frequency=262Hz), we have to make PWM to output square wave with -wavelength 1/262 = 3.8ms: - -|1| - -| We use PWM to output sound wave with different frequency, so as to - play music by the buzzer. -| Connect the buzzer to the PWM output pin shown in the following - diagrams. - -**AMB82 MINI** wiring diagram: - -|image1| - -| Open the example code in “Examples” -> “AmebaAnalog” -> - “:mark:`PWM_BuzzerPlayMelody`” -| Compile and upload to Ameba, press the reset button. Then you can hear - the buzzer playing music. - -Code Reference - -| Ameba implement the tone() and noTone() API of Arduino: -| https://www.arduino.cc/en/Reference/Tone -| https://www.arduino.cc/en/Reference/NoTone - -In the sample code, we initiate a melody array, which stores the tones -to make. Another array, noteDurations, contains the length of each tone, -4 represents quarter note (equals to 3000ms/4 = 750ms, and plus an extra -30% time pause), 8 represents eighth note. - -.. |1| image:: ../../_static/Example_Guides/PWM_-_Buzzer_Play_Melody/PWM_-_Buzzer_Play_Melody_images/image01.png - :width: 6.26806in - :height: 1.62431in -.. |image1| image:: ../../_static/Example_Guides/PWM_-_Buzzer_Play_Melody/PWM_-_Buzzer_Play_Melody_images/image02.png - :width: 3.63636in - :height: 3.00628in diff --git a/bak/Example_Guides/PWM - Buzzer Play Melody/PWM_Servo_Control.rst b/bak/Example_Guides/PWM - Buzzer Play Melody/PWM_Servo_Control.rst deleted file mode 100644 index fbf6f32..0000000 --- a/bak/Example_Guides/PWM - Buzzer Play Melody/PWM_Servo_Control.rst +++ /dev/null @@ -1,47 +0,0 @@ -Preparation - -- AmebaPro2 [AMB82 MINI] x 1 - -- Servo x 1 (Ex. Tower Pro SG90) - -Example - -A typical servo has 3 wires, the red wire is for power, black or brown -one should be connected to GND, and the other one is for signal data. We -use PWM signal to control the rotation angle of the axis of the servo. -The frequency of the signal is 50Hz, that is length 20ms. Each servo -defines its pulse bandwidth, which is usually 1ms~2ms. - -To control the rotation angle, for example if 1ms-length pulse rotates -the axis to degree 0, then 1.5 ms pulse rotates the axis to 90 degrees, -and 2 ms pulse rotates the axis to 180 degrees. Furthermore, a servo -defines the “dead bandwidth”, which stands for the required minimum -difference of the length of two consecutive pulse for the servo to work. - -**AMB82 MINI** wiring diagram: - -|image1| - -| Open the example, “File” -> “Examples” -> “AmebaAnalog” -> - “:mark:`PWM_ServoControl`” -| This example makes the servo to rotate from degree 0 to 180, and then - rotate back to degree 0. - -Code Reference - -The Servo API of Ameba is similar to the API of Arduino. To distinguish -from the original API of Arduino, we name the header file “AmebaServo.h” -and the Class “AmebaServo”, the usage is identical to the Arduino API. - -The default pulse bandwidth of Arduino Servo is 0.5ms~2.4ms, which is -the same as Tower Pro SG90. Therefore, we set the attached pin directly: - -myservo.attach(9); - -Next, rotate the axis to desired position: - -myservo.write(pos); - -.. |image1| image:: ../../_static/Example_Guides/PWM_-_Servo_Control/PWM_Servo_Control_images/image01.png - :width: 4.40095in - :height: 3.51991in diff --git a/bak/Example_Guides/PowerMode - Deep Sleep Mode/PowerMode - Deep Sleep Mode.rst b/bak/Example_Guides/PowerMode - Deep Sleep Mode/PowerMode - Deep Sleep Mode.rst deleted file mode 100644 index 50f39b0..0000000 --- a/bak/Example_Guides/PowerMode - Deep Sleep Mode/PowerMode - Deep Sleep Mode.rst +++ /dev/null @@ -1,125 +0,0 @@ -Materials -========= - -- Ameba Pro2 [AMB82-Mini] x 1 - -.. - - Optional - -- Push button x 1 - -- Register 220 ohms x 1 - -Example -======== - -Introduction ------------- - -In this example, the development board will demo the Deep Sleep Mode for -power save. There are 3 wake-up sources for Deep Sleep Mode which are: -AON Timer, AON GPIO, and RTC. The system will count down 5s then go to -Deep Sleep mode. Upon the wake-up source being tiggered, the system will -be reboot and wake up again. - -The module and board power consumption report under Deep Sleep mode are -listed in these two tables below. For further information about how to -measure the module’s power consumption, please refer to *Ameba FAQ*. - -+------------+---------------------------------------------------------+ -| **Wake-up | **Module power consumption | -| source** | (uA)** | -+============+=========================================================+ -| | Deep Sleep Mode (measure at 3V3) | -+------------+---------------------------------------------------------+ -| AON timer | 32.78 | -+------------+---------------------------------------------------------+ -| AON GPIO | 40.98 | -+------------+---------------------------------------------------------+ -| RTC | 41.08 | -+------------+---------------------------------------------------------+ - -**RTL8735B module power consumption test results** - -+------------+----------------------------+----------------------------+ -| **Wake-up | **Development board power | | -| source** | consumption Approximate | | -| | measurement | | -| | (mA)** | | -+============+============================+============================+ -| | Normal Mode | Standby Mode | -+------------+----------------------------+----------------------------+ -| AON timer | 53.01 | 4.59 | -+------------+----------------------------+----------------------------+ -| AON GPIO | 52.97 | 4.74 | -+------------+----------------------------+----------------------------+ -| RTC | 53.05 | 4.65 | -+------------+----------------------------+----------------------------+ - -**AMB82-MINI board Power Consumption** - -Procedure ---------- - -Open example in “File” -> “Examples” -> “AmebaPowerMode” -> -“DeepSleepMode”. - -|Graphical user interface, application Description automatically -generated| - -Next is setting up the system and entering the power mode. Please refer -to the following steps for entering Deep Sleep mode. - -Step 1. Set up the “WAKEUP_SOURCE”, AON timer: 0; AON GPIO: 1; RTC: 2. - -Step 2. Set up the wake-up source setting. There are 3 wake-up sources, -each one has its own settings. - -For AON timer, at section ”#if (WAKEUP_SOURCE == 0)”, set value to -“CLOCK” and “SLEEP_DURATION”. “CLOCK” can be 4MHz or 100kHz. -“SLEEP_DURATION” unit is in seconds. - -For AON GPIO, at section “#elif (WAKEUP_SOURCE == 1)”, set value to -“WAKUPE_SETTING”. “WAKUPE_SETTING” in this case is the Pin number, that -can be 21 or 22. The GPIO pin is set to active high, please refer to the -following connection. - -|image1| - -For RTC, at section “#elif (WAKEUP_SOURCE == 2)”, set value to -“ALARM_DAY”, “ALARM_HOUR”, “ALARM_MIN”, or “ALARM_SEC”. All alarm values -set the duration of RTC wake-up. The range is “1day, 0h, 0m, 0s” to -“365day, 23h, 59min, 59s”. - -Step 3. Start the Deep Sleep mode. There is only 1 optional setting for -this step. When the wake-up source is set to RTC, use -“PowerMode.start(1970, 1, 1, 0, 0, 0);” to replace “PowerMode.start();” -for setting the start time. (Default is 1970.1.1 00:00:00). - -|Graphical user interface, text Description automatically generated| - -To wake up, all timers will automatically wake up when the duration is -finished, all GPIO pins must active high by pressing the push button. - -The correct boot, enter deep sleep, and reboot cycle will be same as -following picture. - -|image2| - -Code Reference - -NA - -.. |Graphical user interface, application Description automatically generated| image:: ../../_static/Example_Guides/PowerMode_-_Deep_Sleep_Mode/PowerMode_-_Deep_Sleep_Mode_images/image01.png - :width: 4.78125in - :height: 6.90341in -.. |image1| image:: ../../_static/Example_Guides/PowerMode_-_Deep_Sleep_Mode/PowerMode_-_Deep_Sleep_Mode_images/image02.png - :width: 4.32941in - :height: 3.60417in -.. |Graphical user interface, text Description automatically generated| image:: ../../_static/Example_Guides/PowerMode_-_Deep_Sleep_Mode/PowerMode_-_Deep_Sleep_Mode_images/image03.png - :width: 5.125in - :height: 4.53748in -.. |image2| image:: ../../_static/Example_Guides/PowerMode_-_Deep_Sleep_Mode/PowerMode_-_Deep_Sleep_Mode_images/image04.png - :width: 4.0414in - :height: 8.19792in diff --git a/bak/Example_Guides/PowerMode - Deep Sleep Mode/PowerMode - Standby Mode.rst b/bak/Example_Guides/PowerMode - Deep Sleep Mode/PowerMode - Standby Mode.rst deleted file mode 100644 index c323a59..0000000 --- a/bak/Example_Guides/PowerMode - Deep Sleep Mode/PowerMode - Standby Mode.rst +++ /dev/null @@ -1,166 +0,0 @@ -Materials -========= - -- Ameba Pro2 [AMB82-Mini] x 1 - -.. - - Optional - -- Push button x 1 - -- Register 220 ohms x 1 - -- USB to ttl serial cable x 1 - -Example -======== - -Introduction ------------- - -In this example, the development board will demo the Standby Mode for -power save. There are 6 wake-up sources The system will count down 5s -then go to Stand By mode. Upon the wake-up source being tiggered, the -system will be reboot and wake up again. - -The module and board power consumption report under Deep Sleep mode are -listed in these two tables below. For further information about how to -measure the module’s power consumption, please refer to *Ameba FAQ*. - -+-----------------------+----------------------------------------------+ -| **Wake-up source** | **Module power consumption** | -| | | -| | **(uA)** | -+=======================+==============================================+ -| | Stand By Mode (measure at 3V3) | -+-----------------------+----------------------------------------------+ -| AON timer | 41.22 | -+-----------------------+----------------------------------------------+ -| AON GPIO | 41.28 | -+-----------------------+----------------------------------------------+ -| RTC | 41.46 | -+-----------------------+----------------------------------------------+ -| PON GPIO | 41.07 | -+-----------------------+----------------------------------------------+ -| UART/Serial1 | 41.32 | -+-----------------------+----------------------------------------------+ -| Gtimer0 | 41.48 | -+-----------------------+----------------------------------------------+ - -**RTL8735B module power consumption test results** - -+-----------------------+-----------------------+----------------------+ -| **Wake-up source** | **Development board | | -| | power consumption** | | -| | | | -| | **Approximate | | -| | measurement (mA)** | | -+=======================+=======================+======================+ -| | Normal Mode | Standby Mode | -+-----------------------+-----------------------+----------------------+ -| AON timer | 53.15 | 4.79 | -+-----------------------+-----------------------+----------------------+ -| AON GPIO | 53.12 | 4.81 | -+-----------------------+-----------------------+----------------------+ -| RTC | 53.11 | 4.75 | -+-----------------------+-----------------------+----------------------+ -| PON GPIO | 55.09 | 4.87 | -+-----------------------+-----------------------+----------------------+ -| UART/Serial1 | 55.61 | 4.79 | -+-----------------------+-----------------------+----------------------+ -| Gtimer0 | 55.59 | 4.83 | -+-----------------------+-----------------------+----------------------+ - -**AMB82-MINI board Power Consumption** - -Procedure ---------- - -Open example in “File” -> “Examples” -> “AmebaPowerMode” -> -“StandbyMode”. - -|Graphical user interface Description automatically generated| - -Next is setting up the system and entering the power mode. Please refer -to the following steps for entering Standby mode. - -Step 1. Set up the “WAKEUP_SOURCE”, AON timer: 0; AON GPIO: 1; RTC: 2, -PON GPIO: 3, UART/Serial1: 4, Gtimer0: 5. - -Step 2. Set up the wake-up source setting. There are 6 wake-up sources, -each one has its own settings. - -For AON timer, at section ”#if (WAKEUP_SOURCE == 0)”, set value to -“CLOCK” and “SLEEP_DURATION”. “CLOCK” can be 4MHz or 100kHz. -“SLEEP_DURATION” unit is in seconds. - -For AON GPIO, at section “#elif (WAKEUP_SOURCE == 1)”, set value to -“WAKUPE_SETTING”. “WAKUPE_SETTING” in this case is the Pin number, that -can be 21 or 22. The GPIO pin is set to active high, please refer to the -following connection. - -|image1| - -For RTC, at section “#elif (WAKEUP_SOURCE == 2)”, set value to -“ALARM_DAY”, “ALARM_HOUR”, “ALARM_MIN”, or “ALARM_SEC”. All alarm values -set the duration of RTC wake-up. The range is “1day, 0h, 0m, 0s” to -“365day, 23h, 59min, 59s”. - -For PON GPIO, at section “#elif (WAKEUP_SOURCE == 3)”, set value to -“WAKUPE_SETTING”. “WAKUPE_SETTING” in this case is the Pin number, that -can be 0 to 11. The GPIO pin is set to active high, please refer to the -following connection. - -|image2| - -For UART/Serial1, there is no setting required. However, USB to ttl -serial cable Tx(green) and Rx(white) pin needs to connect to Serial1 Rx -and Tx pin. Refer to the following connection. (Power 5V/3.3V Red, -Ground Black) - -|A picture containing diagram Description automatically generated| - -For Gtimer0, at section “#elif (WAKEUP_SOURCE == 5)”, set value to -“SLEEP_DURATION”. “SLEEP_DURATION” is the timer sleep duration in -seconds. - -Step 3. Start the Standby mode. There is only 1 optional setting for -this step. When the wake-up source is set to RTC, use -“PowerMode.start(1970, 1, 1, 0, 0, 0);” to replace “PowerMode.start();” -for setting the start time. (Default is 1970.1.1 00:00:00). - -|Graphical user interface Description automatically generated with -medium confidence| - -To wake up, all timers will automatically wake up when the duration is -finished, all GPIO pins must active high by pressing the push button, -UART needs to give input by Serial1 though USB-ttl cable. - -The correct boot, enter Standby, and reboot cycle will be same as -following picture. - -|Table Description automatically generated with medium confidence| - -Code Reference - -NA - -.. |Graphical user interface Description automatically generated| image:: ../../_static/Example_Guides/PowerMode_-_Standby_Mode/PowerMode_-_Standby_Mode_images/image01.png - :width: 3.66422in - :height: 5.41667in -.. |image1| image:: ../../_static/Example_Guides/PowerMode_-_Standby_Mode/PowerMode_-_Standby_Mode_images/image02.png - :width: 4.32941in - :height: 3.60417in -.. |image2| image:: ../../_static/Example_Guides/PowerMode_-_Standby_Mode/PowerMode_-_Standby_Mode_images/image03.png - :width: 4.42671in - :height: 3.69792in -.. |A picture containing diagram Description automatically generated| image:: ../../_static/Example_Guides/PowerMode_-_Standby_Mode/PowerMode_-_Standby_Mode_images/image04.png - :width: 4.40625in - :height: 6.0877in -.. |Graphical user interface Description automatically generated with medium confidence| image:: ../../_static/Example_Guides/PowerMode_-_Standby_Mode/PowerMode_-_Standby_Mode_images/image05.png - :width: 4.78125in - :height: 5.71561in -.. |Table Description automatically generated with medium confidence| image:: ../../_static/Example_Guides/PowerMode_-_Standby_Mode/PowerMode_-_Standby_Mode_images/image06.png - :width: 4.39583in - :height: 7.30006in diff --git a/bak/Example_Guides/RTC - Simple RTC/RTC - Simple RTC Alarm.rst b/bak/Example_Guides/RTC - Simple RTC/RTC - Simple RTC Alarm.rst deleted file mode 100644 index 58fbb58..0000000 --- a/bak/Example_Guides/RTC - Simple RTC/RTC - Simple RTC Alarm.rst +++ /dev/null @@ -1,34 +0,0 @@ -Materials - -- AmebaPro2 [AMB82 MINI] x 1 - -Example - -This example demonstrates how to use the RTC library methods to create a -RTC Alarm, so that to do some tasks when an alarm is matched. In -particular, the RTC time is set at 16:00:00 and an alarm at 16:00:10. -When the time matches, “Alarm Match” information will be printed on the -serial monitor. - -First, select the correct Ameba development board from the Arduino IDE: -“Tools” -> “Board”. - -Then open the” RTCAlarm” example from: “File” -> “Examples” -> “RTC” -> -“Simple_RTC_Alarm”: - -|image1| - -In the example, the RTC time is set at 16:00:00 and an alarm is set at -16:00:10. Upon successfully upload the sample code and press the reset -button. When the alarm time (10 seconds) is reached the attached -interrupt function will print the following information: “Alarm -Matched!” showing in this figure below. - -|1| - -.. |image1| image:: ../../_static/Example_Guides/RTC_-_Simple_RTC_Alarm/RTC_-_Simple_RTC_Alarm_images/image01.png - :width: 3.63019in - :height: 5.02379in -.. |1| image:: ../../_static/Example_Guides/RTC_-_Simple_RTC_Alarm/RTC_-_Simple_RTC_Alarm_images/image02.png - :width: 6.22639in - :height: 3.31319in diff --git a/bak/Example_Guides/RTC - Simple RTC/RTC - Simple RTC.rst b/bak/Example_Guides/RTC - Simple RTC/RTC - Simple RTC.rst deleted file mode 100644 index 938a52f..0000000 --- a/bak/Example_Guides/RTC - Simple RTC/RTC - Simple RTC.rst +++ /dev/null @@ -1,34 +0,0 @@ -Materials - -- AmebaPro2 [AMB82 MINI] x 1 - -Example - -This example demonstrates how to use the RTC library methods. This -function describes how to use the RTC API. The RTC function is -implemented by an independent BCD timer/counter. - -| Select the correct Ameba development board from the Arduino IDE: - “Tools” -> “Board”. -| Then open the “RTC” example from:”File” -> “Examples” -> “AmebaRTC” -> - “Simple_RTC “: - -|image1| - -Upon successfully upload the sample code and press the reset button, -this example will print out time information since the user initialized -time every second in the Serial Monitor. - -|1| - -Code Reference - -| [1] Simple RTC example from Arduino Tutorials: -| https://www.arduino.cc/en/Tutorial/SimpleRTC - -.. |image1| image:: ../../_static/Example_Guides/RTC_-_Simple_RTC/RTC_-_Simple_RTC_images/image01.png - :width: 4.23483in - :height: 5.86055in -.. |1| image:: ../../_static/Example_Guides/RTC_-_Simple_RTC/RTC_-_Simple_RTC_images/image02.png - :width: 6.21736in - :height: 3.38264in diff --git a/bak/Example_Guides/SPI - LCD Screen ILI9341 TFT/SPI - LCD Screen ILI9341 TFT.rst b/bak/Example_Guides/SPI - LCD Screen ILI9341 TFT/SPI - LCD Screen ILI9341 TFT.rst deleted file mode 100644 index 6e3b91d..0000000 --- a/bak/Example_Guides/SPI - LCD Screen ILI9341 TFT/SPI - LCD Screen ILI9341 TFT.rst +++ /dev/null @@ -1,164 +0,0 @@ -If you are not familiar with SPI, please read `Introduction to -SPI `__ first. - -  - -Preparation - -- AmebaPro2 [AMB82 MINI] x 1 - -- ILI9341 TFT LCD with SPI interface x 1 - -Example - -We have tested the following two models of ILI9341 TFT LCD with SPI -interface: - -- Adafruit 2.8″ TFT LCD (with touch screen) - - - https://www.adafruit.com/products/1651 - - - https://learn.adafruit.com/adafruit-2-8-tft-touch-shield-v2?view=all - -- QVGA 2.2″ TFT LCD - - - http://www.lcdwiki.com/2.2inch_SPI_Module_ILI9341_SKU:MSP2202 - -Common pins in ILI9341 TFT LCD with SPI interface: - -- MOSI: Standard SPI Pin - -- MISO: Standard SPI Pin - -- SLK: Standard SPI Pin - -- CS: Standard SPI Pin - -- RESET: Used to reboot LCD. - -- D/C: Data/Command. When it is at LOW, the signal transmitted are - commands, otherwise the data transmitted are data. - -- LED (or BL): Adapt the screen backlight. Can be controlled by PWM or - connected to VCC for 100% backlight. - -- VCC: Connected to 3V or 5V, depends on its spec. - -- GND: Connected to GND. - -**:mark:` -`** - -**AMB82 MINI and QVGA TFT LCD Wiring** **Diagram:** - -|image1| - -**AMB82 MINI and Adafruit 2.8” TFT LCD touch** **shield:** - -|image2| - -Please note that this shield model enables the backlight by default and -pin 8 is not for backlight, and the VCC should be connected to 5V. - -Open the example, “File” -> “Examples”-> “AmebaSPI” -> -“LCD_Screen_ILI9341_TFT” - -|Graphical user interface, application Description automatically -generated| - -| Compile and upload to Ameba, then press the reset button. -| Then you can see some display tests appear on the LCD screen, such as - displaying different colors, drawing vertical and horizontal lines, - drawing circles, etc.… - -|4| - -:mark:`Besides, it can also display any user images based on the screen -size. Using the online Image converting tool -`here `__ -that supports input images in png, .jpg and .gif ad output as .c file. -Upon converting is done, place the .c file in our template Amebalogo.h -file and upload the code again.` - -|A picture containing text, screenshot, graphic design Description -automatically generated|\ |image3| :mark:`u` - -Code Reference - -- |  **RGB 16-bit** - | ILI9341 uses RGB 16-bit to display colors. Different from RGB - 24-bit, it uses 5 bits for red, 6 bits for green, 5 bits for blue. - For example, the RGB 24-bit representation of sky blue is 0x87CEFF, - that is in binary: - - - Red: 0x87 = B10000111 - - - Green: 0xCE = B11001110 - - - Blue: 0xFF = B11111111 - -.. - - and converted to RGB 16-bit: - -- Red: B10000 - -- Green: B110011 - -- Blue: B11111 - -.. - - Then concatenate them, which forms B1000011001111111 = 0x867F - -- **Drawing of ILI9341** - - - First you must specify the range of the rectangle to draw, then - pass the 2-byte RGB 16-bit color to ILI9341 corresponding to each - pixel one by one, in this way ILI9341 fills each color to each - pixel. - - - You still must specify the drawing range even though the range - covers only one pixel. - - - From the rules we mentioned above, we can conclude that drawing - vertical or horizontal lines are faster than diagonal lines. - -- **Printing text on ILI9341** - - - In our API, each character is 5×7 but each character is printed to - size 6×8 (its right side and below are left blank), so as to - separate from next character. For example, the character “A”:|5| - - - The font size represents the dot size. For example, if the font - size is 2, each dot in the character is a 2×2 rectangle - -- **Screen rotation** - - - ILI9341 provides 0, 90, 180, 270 degrees screen rotation. - - - If the original width is 240 and original height is 320, when the - screen rotates 90 degrees, the width becomes 320 and the height - becomes 240. - -.. |image1| image:: ../../_static/Example_Guides/SPI_-_LCD_Screen_ILI9341_TFT/SPI_-_LCD_Screen_ILI9341_TFT_images/image01.png - :width: 6.26806in - :height: 3.64407in -.. |image2| image:: ../../_static/Example_Guides/SPI_-_LCD_Screen_ILI9341_TFT/SPI_-_LCD_Screen_ILI9341_TFT_images/image02.png - :width: 6.14998in - :height: 4.12569in -.. |Graphical user interface, application Description automatically generated| image:: ../../_static/Example_Guides/SPI_-_LCD_Screen_ILI9341_TFT/SPI_-_LCD_Screen_ILI9341_TFT_images/image03.png - :width: 5.08696in - :height: 5.93516in -.. |4| image:: ../../_static/Example_Guides/SPI_-_LCD_Screen_ILI9341_TFT/SPI_-_LCD_Screen_ILI9341_TFT_images/image04.png - :width: 6.26806in - :height: 2.00972in -.. |A picture containing text, screenshot, graphic design Description automatically generated| image:: ../../_static/Example_Guides/SPI_-_LCD_Screen_ILI9341_TFT/SPI_-_LCD_Screen_ILI9341_TFT_images/image5.jpeg - :width: 2.79167in - :height: 1.45787in -.. |image3| image:: ../../_static/Example_Guides/SPI_-_LCD_Screen_ILI9341_TFT/SPI_-_LCD_Screen_ILI9341_TFT_images/image06.png - :width: 2.88542in - :height: 4.11875in -.. |5| image:: ../../_static/Example_Guides/SPI_-_LCD_Screen_ILI9341_TFT/SPI_-_LCD_Screen_ILI9341_TFT_images/image07.png - :width: 2.06944in - :height: 2.76736in diff --git a/source/Example_Guides/GPIO/Interrupt Control LED.rst b/source/Example_Guides/GPIO/Interrupt Control LED.rst new file mode 100644 index 0000000..2abd148 --- /dev/null +++ b/source/Example_Guides/GPIO/Interrupt Control LED.rst @@ -0,0 +1,87 @@ +Interrupt Control LED +===================== + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +- Button x 1 + +Example +------- + +In this example, we use a button to trigger interrupt and control the LED. +When we press and release the button, the LED dims, press and release the button again, and the LED lights up.Note that in the Arduino example “Button and LED”, LED only lights up when the button is pressed and hold, when we release the button, the LED dims. + +Open the example, “File” -> “Example” -> “AmebaGPIO” -> “Interrupt_Ctrl_LED” + +|image01| + +Since there is no in-built push button on AmebaPro2 [AMB82 MINI], you may choose to change the code highlighted in yellow to any GPIO pin number. In this example, GPIO pin 0 is used. + +|image02| + +**AMB82 MINI wiring diagram:** + +|image03| + +| Compile and upload the program, press the reset button on the Ameba. +| The LED will light up at first. Press and release the button, then the LED should dim. Press the button again the LED should light up. + +Code Reference +-------------- + +In + +.. code-block:: c++ + + setup() + +we set the GPIO pin in the above example to + +.. code-block:: c++ + + INPUT_IRQ_RISE + +, this means that an interrupt occurs when the voltage of this pin changes from GND to 3V3. Therefore, we connect the other side of the button to 3V3, so as to trigger interrupt event when the button is pressed. + +.. code-block:: c++ + + pinMode(button, INPUT_IRQ_RISE); + +On the other hand, we can set the GPIO pin in the above example to + +.. code-block:: c++ + + INPUT_IRQ_FALL + +, this means that an interrupt occurs when the voltage of this pin changes from 3V3 to GND. In this case, the other side of the button is connected to GND. Next, we need to specify the function to be executed to handle the interrupt: + +.. code-block:: c++ + + digitalSetIrqHandler(button, button_handler); + +The second parameter is a function pointer, with prototype: + +.. code-block:: c++ + + void button_handler(uint32_t id, uint32_t event) + +In this handler, every time we press and release the button, we trigger an interrupt, and change the status of the LED. + +.. |image01| image:: ../../_static/Example_Guides/GPIO/Interrupt_Control_LED/image01.png + :width: 602 px + :height: 720 px + +.. |image02| image:: ../../_static/Example_Guides/GPIO/Interrupt_Control_LED/image02.png + :width: 602 px + :height: 737 px + +.. |image03| image:: ../../_static/Example_Guides/GPIO/Interrupt_Control_LED/image03.png + :width: 958 px + :height: 455 px diff --git a/source/Example_Guides/GPIO/Measure Distance HCSR04 Ultrasonic.rst b/source/Example_Guides/GPIO/Measure Distance HCSR04 Ultrasonic.rst new file mode 100644 index 0000000..cdfc39c --- /dev/null +++ b/source/Example_Guides/GPIO/Measure Distance HCSR04 Ultrasonic.rst @@ -0,0 +1,91 @@ +Measure Distance HCSR04 Ultrasonic +================================== + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +- HC-SR04 Ultrasonic x 1 + +- Dropping resistor or Level converter + +Example +------- + +| HC-SR04 is a module that uses ultrasound to measure the distance. It looks like a pair of eyes in its appearance, therefore it’s often installed onto robot-vehicle or mechanical bugs to be their eyes. +| The way it works is that first we “toggle high” the TRIG pin (that is to pull high then pull low). The HC-SR04 would send eight 40kHz sound wave signal and pull high the ECHO pin. When the sound wave returns, it pull low the ECHO pin. + +|image01| + +| Assume the velocity of sound is 340 m/s, the time it takes for the sound to advance 1 cm in the air is 340*100*10^-6 = 29 us。 +| The sound wave travels twice the distance between HC-SR04 and the object, therefore the distance can be calculated by (time/29) / 2 = time / 58。 +| The working voltage of HC-SR04 is 5V. When we pull high the ECHO pin to 5V, the voltage might cause damage to the GPIO pin of Ameba. To avoid this situation, we need to drop the voltage as follows: + +**AMB82 MINI** Wiring Diagram: + +|image02| + +| We pick the resistors with resistance 1:2, any value of resistance is fine but not recommended too high values. +| If you do not have resistors in hand, you can use level converter instead.The TXB0108 8 channel level converter is a suitable example: + +**AMB82 MINI** Wiring Diagram: + +|image03| + +Next, open the sample code in “File” -> “Examples” -> “AmebaGPIO” -> “HCSR04_Ultrasonic” + +|image04| + +Compile and upload to Ameba, then press the reset button. Open the Serial Monitor, the calculated result is output to serial monitor every 2 seconds. + +|image05| + +Note that the HCSR04 module uses the reflection of sound wave to calculate the distance, thus the result can be affected by the surface material of the object (e.g., harsh surface tends to cause scattering of sound wave, and soft surface may cause the sound wave to be absorbed). + +Code Reference +-------------- + +Before the measurement starts, we need to pull high the TRIG pin for 10us and then pull low. By doing this, we are telling the HC-SR04 that we are about to start the measurement: + +.. code-block:: c++ + + digitalWrite(trigger_pin, HIGH); + delayMicroseconds(10); + digitalWrite(trigger_pin, LOW); + +Next, use pulseIn to measure the time when the ECHO pin is pulled high. + +.. code-block:: c++ + + duration = pulseIn (echo_pin, HIGH); + +Finally, use the formula to calculate the distance. + +.. code-block:: c++ + + distance = duration / 58; + +.. |image01| image:: ../../_static/Example_Guides/GPIO/Measure_Distance_HCSR04_Ultrasonic/image01.png + :width: 882 px + :height: 543 px + +.. |image02| image:: ../../_static/Example_Guides/GPIO/Measure_Distance_HCSR04_Ultrasonic/image02.png + :width: 1027 px + :height: 626 px + +.. |image03| image:: ../../_static/Example_Guides/GPIO/Measure_Distance_HCSR04_Ultrasonic/image03.png + :width: 1029 px + :height: 624 px + +.. |image04| image:: ../../_static/Example_Guides/GPIO/Measure_Distance_HCSR04_Ultrasonic/image04.png + :width: 602 px + :height: 849 px + +.. |image05| image:: ../../_static/Example_Guides/GPIO/Measure_Distance_HCSR04_Ultrasonic/image05.png + :width: 649 px + :height: 372 px diff --git a/source/Example_Guides/GPIO/Measure Temperature and Humidity DHT Tester.rst b/source/Example_Guides/GPIO/Measure Temperature and Humidity DHT Tester.rst new file mode 100644 index 0000000..771645a --- /dev/null +++ b/source/Example_Guides/GPIO/Measure Temperature and Humidity DHT Tester.rst @@ -0,0 +1,79 @@ +Measure Temperature and Humidity DHT Tester +=========================================== + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +- DHT11 or DHT22 or DHT21 + +Example +------- + +| DHT11 is a temperature and humidity sensor which operates at voltage 3.3V~5V. At room temperature, the measurable range of the humidity is 20% ~ 90%RH with ±5%RH precision, the measurable range of the temperature is 0 ~ 50℃ with ±2℃ precision. +| Another choice of temperature and humidity sensor is DHT22 sensor, which has better precision. Its measurable range of the humidity is 0%~100%RH with ±5%RH precision, the measurable range of the temperature is -40~125 ℃ with ±0.2℃ precision. +| There are 4 pins on the sensor: + +|image01| + +Since one of the 4 pins has no function, there are temperature/humidity sensors with only 3 pins on the market: + +|image02| + +DHT is normally in the sleeping mode. To get the temperature/humidity data, please follow the steps: + +| Awake DHT: Ameba toggles low its DATA pin of GPIO. Now the DATA pin of GPIO serves as digital out to Ameba. +| DHT response: DHT also toggle low its DATA pin of GPIO. Now the DATA pin of GPIO serves as digital in for Ameba. +| DHT sends data: DHT sends out the temperature/humidity data (which has size 5 bytes) in a bit by bit manner. To represent each bit, DHT first pull low the DATA GPIO pin for a while and then pull high. If the duration of high is smaller than low, it stands for bit 0. Otherwise it stands for bit 1. + +|image03| + +Take note that if you are using a DHT sensor that is not mounted on a PCB, you will have to add in a 10K Ohm pull up resistor. You may refer to the wiring diagrams. + +**AMB82 wiring diagram:** +**DHT sensor not mounted on a PCB board** + +|image04| + +**DHT sensor mounted on a PCB board** + +|image05| + +Open the sample code in “Files” -> “Examples” -> “AmebaGPIO” -> “DHT_Tester”. Compile and upload to Ameba, then press the reset button. The result would be shown on the Serial Monitor. + +|image06| + +Code Reference +-------------- + +| Use dht.readHumidity() read the humidity value, and use dht.readTemperature() to read the temperature value. +| Every time we read the temperature/humidity data, Ameba uses the buffered temperature/humidity data unless it found the data has expired (i.e., has not been updated for over 2 seconds). If the data is expired, Ameba issues a request to DHT to read the latest data. + +.. |image01| image:: ../../_static/Example_Guides/GPIO/Measure_Temperature_and_Humidity_DHT_Tester/image01.png + :width: 405 px + :height: 519 px + +.. |image02| image:: ../../_static/Example_Guides/GPIO/Measure_Temperature_and_Humidity_DHT_Tester/image02.png + :width: 178 px + :height: 432 px + +.. |image03| image:: ../../_static/Example_Guides/GPIO/Measure_Temperature_and_Humidity_DHT_Tester/image03.png + :width: 965 px + :height: 280 px + +.. |image04| image:: ../../_static/Example_Guides/GPIO/Measure_Temperature_and_Humidity_DHT_Tester/image04.png + :width: 739 px + :height: 370 px + +.. |image05| image:: ../../_static/Example_Guides/GPIO/Measure_Temperature_and_Humidity_DHT_Tester/image05.png + :width: 702 px + :height: 572 px + +.. |image06| image:: ../../_static/Example_Guides/GPIO/Measure_Temperature_and_Humidity_DHT_Tester/image06.png + :width: 704 px + :height: 591 px diff --git a/source/Example_Guides/GPIO/index.rst b/source/Example_Guides/GPIO/index.rst new file mode 100644 index 0000000..a1c02e3 --- /dev/null +++ b/source/Example_Guides/GPIO/index.rst @@ -0,0 +1,9 @@ +GPIO +==== + +.. toctree:: + :maxdepth: 1 + + Interrupt Control LED + Measure Distance HCSR04 Ultrasonic + Measure Temperature and Humidity DHT Tester \ No newline at end of file diff --git a/source/Example_Guides/GTimer/Timer Oneshot.rst b/source/Example_Guides/GTimer/Timer Oneshot.rst new file mode 100644 index 0000000..d5b3d28 --- /dev/null +++ b/source/Example_Guides/GTimer/Timer Oneshot.rst @@ -0,0 +1,39 @@ +Timer Oneshot +============= + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +Example +------- + +In this example, we will use 4 One-Time GTimer, and pass user data to each timer. + +Open the example “File” -> “Examples” -> “AmebaGTimer” -> “TimerOneshot”. Compile and upload to Ameba, and press reset. Then you can see the 4 timer log printed to the serial monitor in series. + + +Code Reference +-------------- + +| The first argument of begin() is the Timer ID (0~3). The second argument is the value of the timer (in microseconds). +| In the example, we fill in 1000000us = 1s. The third argument specifies the function to call when the time is up. +| The fourth argument is to set whether this timer is a periodic timer, we use “false” here to begin a single-use timer. +| The fifth argument is the user data, we give 0 here to represent that this is timer 0. + +.. code-block:: c++ + + GTimer.begin(0, 1 * 1000 * 1000, myhandler, false, 0); + +Next, we set up the second timer, which has timer value 2 seconds, and user data 1. And other timers are set similarly. + +.. code-block:: c++ + + GTimer.begin(1, 2 * 1000 * 1000, myhandler, false, 1); + +In myhandler function, we print the user data to serial monitor. Since the 4 timers are separately set to count for 1, 2, 3, 4 seconds, from 1 second to 4 second, the user data of each timer are printed on the serial monitor in order. After 4 second, no log will be printed. diff --git a/source/Example_Guides/GTimer/Timer Periodical.rst b/source/Example_Guides/GTimer/Timer Periodical.rst new file mode 100644 index 0000000..30ef898 --- /dev/null +++ b/source/Example_Guides/GTimer/Timer Periodical.rst @@ -0,0 +1,38 @@ +Timer Periodical +================ + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +Example +------- + +Ameba provides 4 hardware GTimer for users to use. The timers’ resolutions are at microseconds scale. +The timer can be set to be periodic or for single use. The periodic timers reset periodically, and the single-use timers do not. + +Open the example, “File” -> “Examples” -> “AmebaGTimer” -> “TimerPeriodical”. Compile and upload to Ameba, and press reset. +In the Serial Monitor, you can see the counter value is increased periodically. + +Code Reference +-------------- + +| The first argument of begin() is the timer id (0~3). +| The second argument is the value of the timer (in microseconds). In the example, we fill in 1000000us = 1s. +| The third argument specifies the function to call when the time is up. In the example, we call the “myhandler” function to increase the counter value by 1 and print the counter value to serial monitor. + +.. code-block:: c++ + + GTimer.begin(0, 1 * 1000 * 1000, myhandler); + +| The GTimer is periodic by default, therefore “myhandler” function is called every second. +| When we want to stop the GTimer, use “stop()”: + +.. code-block:: c++ + + GTimer.stop(0); \ No newline at end of file diff --git a/source/Example_Guides/GTimer/index.rst b/source/Example_Guides/GTimer/index.rst new file mode 100644 index 0000000..7d170a7 --- /dev/null +++ b/source/Example_Guides/GTimer/index.rst @@ -0,0 +1,8 @@ +GTimer +====== + +.. toctree:: + :maxdepth: 1 + + Timer Oneshot + Timer Periodical diff --git a/source/Example_Guides/MQTT/Set up MQTT Client over TLS.rst b/source/Example_Guides/MQTT/Set up MQTT Client over TLS.rst new file mode 100644 index 0000000..b941927 --- /dev/null +++ b/source/Example_Guides/MQTT/Set up MQTT Client over TLS.rst @@ -0,0 +1,66 @@ +Set up MQTT Client over TLS +=========================== + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +Example +------- + +In this example, Ameba connect to a MQTT broker using TLS authentication. Then send messages as a publisher and receive messages as a subscriber. + +Open example at “File” -> “Examples” -> “AmebaMQTTClient” -> “MQTT_TLS” + +Please modify the WiFi-related parameters and MQTT parameters. + +|image01| + +- “ssid” is the network SSID for internet access. + +- “pass” is the network password for internet access. + +- The “mqttServer” refers to the MQTT-Broker, there is free MQTT + sandbox “test.mosquitto.org” for testing. + +- “clientId” is an identifier for MQTT-Broker to identify the connected + device. + +- “publishTopic” is the topic of the published message. It is + “outTopic” in the example. The devices that subscribed to “outTopic” + will receive the message. + +- “publishPayload” is the content to be published. + +- “subscribeTopic” is to tell MQTT-broker which topic to subscribe to + by the board. + +Next, compile the code and upload it to Ameba. Press the reset button, +then open the serial monitor. + +|image02| + +After Ameba is connected to MQTT server, it sends the message “hello world” to “outTopic”. To see the message, use another MQTT client. Refer to the MQTT_Basic example guide on how to setup a PC-based MQTT client. + +In addition to use TLS client authentication to server authentication, it requires to generate an OpenSSL private key and obtain a signed certificate from the server. For testing purposes, signed certificates can be obtained from test.mosquitto.org by following the guide at https://test.mosquitto.org/ssl/. + +Replace the character strings “certificateBuff” and “privateKeyBuff” with the signed certificate and OpenSSL private key, ensuring that they are formatted the same way as the shown in the example code. Set “MQTT_TLS_SERVER_AUTH” to be “1”. + +|image03| + +.. |image01| image:: ../../_static/Example_Guides/MQTT/Set_up_Client_TLS/image01.png + :width: 519 px + :height: 240 px + +.. |image02| image:: ../../_static/Example_Guides/MQTT/Set_up_Client_TLS/image02.png + :width: 723 px + :height: 417 px + +.. |image03| image:: ../../_static/Example_Guides/MQTT/Set_up_Client_TLS/image03.png + :width: 256 px + :height: 51 px diff --git a/source/Example_Guides/MQTT/Set up MQTT Client to Communicate with Broker.rst b/source/Example_Guides/MQTT/Set up MQTT Client to Communicate with Broker.rst new file mode 100644 index 0000000..af7edc9 --- /dev/null +++ b/source/Example_Guides/MQTT/Set up MQTT Client to Communicate with Broker.rst @@ -0,0 +1,218 @@ +Set up MQTT Client to Communicate with Broker +============================================== + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +Example +------- + +MQTT (Message Queuing Telemetry Transport) is a protocol proposed by IBM and Eurotech. The introduction in MQTT Official Website: +MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport.We can say MQTT is a protocol designed for IoT. MQTT is based on TCP/IP and transmits/receives data via publish/subscribe. + +Please refer to the figure below: + +|image01| + +In the operation of MQTT, there are several roles: + +- Publisher: Usually publishers are the devices equipped with sensors + (ex. Ameba). Publishers uploads the data of the sensors to + MQTT-Broker, which serves as a database with MQTT service. + +- Subscriber: Subscribers are referred to the devices which receive and + observe messages, such as a laptop or a mobile phone. + +- Topic: Topic is used to categorize the messages, for example the + topic of a message can be “PM2.5” or “Temperature”. Subscribers can + choose messages of which topics they want to receive. + +In this page, there are 3 examples that connect Ameba to MQTT-Broker. +Then send messages as publisher and receive messages from MQTT-Broker as +subscriber. + +1. MQTT_Basic + +2. MQTT_Auth + +3. MQTT_Publish_In_Callback + +**MQTT_Basic example** + +| Open the MQTT example “File” -> “Examples” -> “AmebaMQTTClient” -> “MQTT_Basic” +| Please modify some WiFi-related parameter and some information related to MQTT: + +|image02| + +- “ssid” is the network SSID for internet access. + +- “pass” is the network password for internet access. + +- “mqttServer” refers to the MQTT-Broker, there is free MQTT sandbox + “test.mosquitto.org” for testing. + +- “clientId” is an identifier for MQTT-Broker to identify the connected + device. + +- “publishTopic” is the topic of the published message in the example + it is “outTopic”. The devices that subscribed to “outTopic” will + receive the message. + +- “publishPayload” is the content to be published. + +- “subscribeTopic” is to tell MQTT-broker which topic to subscribe to + by the board. + +Next, compile the code and upload it to Ameba. Press the reset button, then open the serial monitor. + +|image03| + +After Ameba is connected to MQTT server, it sends the message “hello world” to “outTopic”. To see the message, another MQTT client needs to be set up. + +The “MQTT Explore” is an all-platform application that can be set as the MQTT client. Refer to the website http://mqtt-explorer.com/. + +Click “Connections” at top left to start a new connection setup. “Name” can be customized. Set “Host” as “test.mosquitto.org”. + +|image04| + +Click “ADVANCED” at bottom for topic setup. Use “outTopic” that same as “publishTopic” of the board. Click “ADD” then “BACK”. + +|image05| + +Click “CONNECT”. The “hello world” message show up at left side. At right side, under “Publish” use “inTopic” same as “sucribeTopic” of the board. Choose “raw” and input “Text hello Ameba”, then click “PUBLISH”. The board will receive the MQTT Explorer published raw message. Note, because of the host is a free public host, the board may receive unexpected messages. + +|image06| + +|image07| + +**MQTT_Auth example** + +| Open the MQTT example “File” -> “Examples” -> “AmebaMQTTClient” -> “MQTT_Auth” +| Please modify some WiFi-related parameter and some information related to MQTT: + +|image08| + +- “mqttServer” refers to the MQTT-Broker, there is free MQTT auth host + provided by amebaiot homepage “cloud.amebaiot.com”. Please visit + https://www.amebaiot.com/en/cloud-getting-started/ for account setup. + +- “clientId” is an identifier for MQTT-Broker to identify the connected + device. In this case, it is the registered device name. Refer to + https://www.amebaiot.com/en/cloud-service/. + +- “clientUser” is the authentication username. In this case, it is the + login username of Realtek IoT/Wi-Fi MCU Solutions website. Note, it + will be unable to receive message if use the email as “clientUser”. + +- “clientPass” is the authentication password. In this case, it is the + login password of Realtek IoT/Wi-Fi MCU Solutions website. + +- The other parameters are same as pervious. + +Next, compile the code and upload it to Ameba. Press the reset button, then open the serial monitor. After Ameba is connected to MQTT server, it sends the message “hello world” to “outTopic”. To see the message, another MQTT client needs to be set up. + +Start the MQTT Explore, and setup the auth connection. + +Click “Connections” at top left to start a new connection setup. “Name” can be customized. Set “Host” as “cloud.amebaiot.com”. “Username” and “Password” are same as “clientUser” and “clientPass”. + +|image09| + +Click “ADVANCED” at bottom for topic setup. Use “outTopic” that same as “publishTopic” of the board. Click “ADD” then “BACK”. + +Click “CONNECT”. The “hello world” message show up at left side. At right side, under “Publish” use “inTopic” same as “sucribeTopic” of the board. Choose “raw” and input “Text hello Ameba”, then click “PUBLISH”. The board will receive the MQTT Explorer published raw message. Note, “hello world” sometimes is not shown up because the boards connect to MQTT broker before the MQTT Explorer. + +|image10| + +|image11| + +**MQTT_Publish_In_Callback example** + +Open the MQTT example “File” -> “Examples” -> “AmebaMQTTClient” -> +“MQTT_Publish_In_Callback” + +Please modify some WiFi-related parameter and some information related +to MQTT: + +- All parameters are same as MQTT_Auth example. + +Next, compile the code and upload it to Ameba. Press the reset button, +then open the serial monitor. After Ameba is connected to MQTT server, +it sends the message “hello world” to “outTopic”. To see the message, +another MQTT client needs to be set up. + +Start the MQTT Explore, and setup the auth connection. All setting is +same as MQTT_Auth example. + +Click “ADVANCED” at bottom for topic setup. Use “outTopic” that same as +“publishTopic” of the board. Click “ADD” then “BACK”. + +Click “CONNECT”. The “hello world” message show up at left side. At +right side, under “Publish” use “inTopic” same as “sucribeTopic” of the +board. Choose “raw” and input “Text hello Ameba”, then click “PUBLISH”. +The board will receive the MQTT Explorer published raw message. Then +publish it from the board side and MQTT Explorer will receive at the +left side. Note, “hello world” sometimes is not shown up because the +boards connect to MQTT broker before the MQTT Explorer. + +|image12| + +|image13| + + +.. |image01| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image01.png + :width: 940 px + :height: 617 px + +.. |image02| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image02.png + :width: 498 px + :height: 182 px + +.. |image03| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image03.png + :width: 662 px + :height: 438 px + +.. |image04| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image04.png + :width: 1002 px + :height: 654 px + +.. |image05| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image05.png + :width: 996 px + :height: 655 px + +.. |image06| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image06.png + :width: 1000 px + :height: 655 px + +.. |image07| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image07.png + :width: 449 px + :height: 142 px + +.. |image08| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image08.png + :width: 524 px + :height: 217 px + +.. |image09| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image09.png + :width: 998 px + :height: 652 px + +.. |image10| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image10.png + :width: 997 px + :height: 667 px + +.. |image11| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image11.png + :width: 538 px + :height: 155 px + +.. |image12| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image12.png + :width: 1001 px + :height: 653 px + +.. |image13| image:: ../../_static/Example_Guides/MQTT/Set_up_Client/image13.png + :width: 548 px + :height: 151 px \ No newline at end of file diff --git a/source/Example_Guides/MQTT/index.rst b/source/Example_Guides/MQTT/index.rst new file mode 100644 index 0000000..10062fe --- /dev/null +++ b/source/Example_Guides/MQTT/index.rst @@ -0,0 +1,8 @@ +MQTT +==== + +.. toctree:: + :maxdepth: 1 + + Set up MQTT Client over TLS + Set up MQTT Client to Communicate with Broker diff --git a/source/Example_Guides/NTP/Retrieve Universal Time (UTC) by NTPClient library.rst b/source/Example_Guides/NTP/Retrieve Universal Time (UTC) by NTPClient library.rst new file mode 100644 index 0000000..fe2ce73 --- /dev/null +++ b/source/Example_Guides/NTP/Retrieve Universal Time (UTC) by NTPClient library.rst @@ -0,0 +1,65 @@ +Retrieve Universal Time (UTC) by NTPClient library +================================================== + +.. contents:: + :local: + :depth: 2 + +Materials +--------- +- `AMB82-mini `_ x 1 + +Example +------- + +In this example, we use an NTP client to sync with NTP servers using UDP and keep track of time locally.Open the example. “File” -> “Examples” -> “NTPClient” -> “Advanced” + +|image01| + +Modify the highlighted code section (ssid, password) to connect to your WiFi network. + +|image02| + +Compile the code and upload it to Ameba. After pressing the Reset button, Ameba connects to WiFi, gets the UTC time from the NTP server, and prints out the current time with time zone offset to the serial monitor. + +|image03| + +Code Reference +-------------- + +| Configure NTP client: +| The NTPClient needs to use a UDP client for communications. A WiFiUDP client is declared and passed to the NTPClient constructor, along with an NTP server address, time zone offset in seconds, and update interval in milliseconds. If detailed configuration is not needed, just passing in the UDP client is also sufficient, refer to the “NTPClient” -> “Basic” example. + +.. code-block:: c++ + + WiFiUDP ntpUDP; + NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); + +| Start NTP client: +| After connecting to WiFi, the NTPClient is started using the begin() function, which causes the client to sync with the NTP server and get the UTC time. + +.. code-block:: c++ + + WiFiUDP ntpUDP; + timeClient.begin(); + +| Get local time: +| getFormattedTime() is used to format the received UTC time into the local time zone. +| update() is called every loop so that the NTPClient will sync with the NTP server once every update interval. + +.. code-block:: c++ + + timeClient.update(); + timeClient.getFormattedTime(); + +.. |image01| image:: ../../_static/Example_Guides/NTP/Retrieve_Universal_Time_(UTC)_by_NTPClient_library/image01.png + :width: 904 px + :height: 479 px + +.. |image02| image:: ../../_static/Example_Guides/NTP/Retrieve_Universal_Time_(UTC)_by_NTPClient_library/image02.png + :width: 779 px + :height: 804 px + +.. |image03| image:: ../../_static/Example_Guides/NTP/Retrieve_Universal_Time_(UTC)_by_NTPClient_library/image03.png + :width: 868 px + :height: 910 px \ No newline at end of file diff --git a/source/Example_Guides/NTP/index.rst b/source/Example_Guides/NTP/index.rst new file mode 100644 index 0000000..a9a708a --- /dev/null +++ b/source/Example_Guides/NTP/index.rst @@ -0,0 +1,8 @@ +NTP +=== + +.. toctree:: + :maxdepth: 1 + + + Retrieve Universal Time (UTC) by NTPClient library \ No newline at end of file diff --git a/source/Example_Guides/PWM/Buzzer Play Melody.rst b/source/Example_Guides/PWM/Buzzer Play Melody.rst new file mode 100644 index 0000000..493afdb --- /dev/null +++ b/source/Example_Guides/PWM/Buzzer Play Melody.rst @@ -0,0 +1,50 @@ +Buzzer Play Melody +================== + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +- Buzzer x 1 + +Example +------- + +A sound is composed of volume, tone and timbre. Volume is determined by the amplitude of the sound wave. Tone is determined by the frequency of the sound wave. Timbre is determined by the waveform of the sound wave. + +In this example, we use PWM to control the buzzer to emit sound with desired tone. As PWM outputs square wave, if we wish to emit tone C4 (frequency=262Hz), we have to make PWM to output square wave with wavelength 1/262 = 3.8ms: + +|image01| + +| We use PWM to output sound wave with different frequency, so as to play music by the buzzer. +| Connect the buzzer to the PWM output pin shown in the following diagrams. + +**AMB82 MINI** wiring diagram: + +|image02| + +| Open the example code in “Examples” -> “AmebaAnalog” -> “PWM_BuzzerPlayMelody” +| Compile and upload to Ameba, press the reset button. Then you can hear the buzzer playing music. + +Code Reference +-------------- + +| Ameba implement the tone() and noTone() API of Arduino: +| https://www.arduino.cc/en/Reference/Tone +| https://www.arduino.cc/en/Reference/NoTone +| In the sample code, we initiate a melody array, which stores the tones to make. Another array, noteDurations, contains the length of each tone, 4 represents quarter note (equals to 3000ms/4 = 750ms, and plus an extra 30% time pause), 8 represents eighth note. + + +.. |image01| image:: ../../_static/Example_Guides/PWM/Buzzer_Play_Melody/image01.png + :width: 710 px + :height: 184 px + +.. |image02| image:: ../../_static/Example_Guides/PWM/Buzzer_Play_Melody/image02.png + :width: 883 px + :height: 730 px + diff --git a/source/Example_Guides/PWM/Servo Control.rst b/source/Example_Guides/PWM/Servo Control.rst new file mode 100644 index 0000000..71324d9 --- /dev/null +++ b/source/Example_Guides/PWM/Servo Control.rst @@ -0,0 +1,47 @@ +Servo Control +============== + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +- Servo x 1 (Ex. Tower Pro SG90) + +Example +------- + +A typical servo has 3 wires, the red wire is for power, black or brown one should be connected to GND, and the other one is for signal data. We use PWM signal to control the rotation angle of the axis of the servo. The frequency of the signal is 50Hz, that is length 20ms. Each servo defines its pulse bandwidth, which is usually 1ms~2ms. + +To control the rotation angle, for example if 1ms-length pulse rotates the axis to degree 0, then 1.5 ms pulse rotates the axis to 90 degrees, and 2 ms pulse rotates the axis to 180 degrees. Furthermore, a servo defines the “dead bandwidth”, which stands for the required minimum difference of the length of two consecutive pulse for the servo to work. + +**AMB82 MINI** wiring diagram: + +|image01| + +| Open the example, “File” -> “Examples” -> “AmebaAnalog” -> “PWM_ServoControl” +| This example makes the servo to rotate from degree 0 to 180, and then rotate back to degree 0. + +Code Reference +-------------- + +| The Servo API of Ameba is similar to the API of Arduino. To distinguish from the original API of Arduino, we name the header file “AmebaServo.h” and the Class “AmebaServo”, the usage is identical to the Arduino API. +| The default pulse bandwidth of Arduino Servo is 0.5ms~2.4ms, which is the same as Tower Pro SG90. Therefore, we set the attached pin directly: + +.. code-block:: c++ + + myservo.attach(9); + +Next, rotate the axis to desired position: + +.. code-block:: c++ + + myservo.write(pos); + +.. |image01| image:: ../../_static/Example_Guides/PWM/Servo_Control/image01.png + :width: 727 px + :height: 581 px \ No newline at end of file diff --git a/source/Example_Guides/PWM/index.rst b/source/Example_Guides/PWM/index.rst new file mode 100644 index 0000000..21c36ca --- /dev/null +++ b/source/Example_Guides/PWM/index.rst @@ -0,0 +1,8 @@ +PWM +=== + +.. toctree:: + :maxdepth: 1 + + Buzzer Play Melody + Servo Control diff --git a/source/Example_Guides/PowerMode/Deep Sleep Mode.rst b/source/Example_Guides/PowerMode/Deep Sleep Mode.rst new file mode 100644 index 0000000..943a048 --- /dev/null +++ b/source/Example_Guides/PowerMode/Deep Sleep Mode.rst @@ -0,0 +1,94 @@ +Deep Sleep Mode +=============== + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +- Optional: Push button x 1 + +- Optional: Register 220 ohms x 1 + +Example +------- + +In this example, the development board will demo the Deep Sleep Mode for power save. There are 3 wake-up sources for Deep Sleep Mode which are: AON Timer, AON GPIO, and RTC. The system will count down 5s then go to Deep Sleep mode. Upon the wake-up source being tiggered, the system will be reboot and wake up again. + +The module and board power consumption report under Deep Sleep mode are listed in these two tables below. + +**RTL8735B module power consumption test results** + ++------------+---------------------------------------------------------+ +| **Wake-up | **Module power consumption | +| source** | (uA)** | ++============+=========================================================+ +| | Deep Sleep Mode (measure at 3V3) | ++------------+---------------------------------------------------------+ +| AON timer | 32.78 | ++------------+---------------------------------------------------------+ +| AON GPIO | 40.98 | ++------------+---------------------------------------------------------+ +| RTC | 41.08 | ++------------+---------------------------------------------------------+ + + +**AMB82 MINI board Power Consumption** + ++------------+----------------------------+----------------------------+ +| **Wake-up | **Development board power | | +| source** | consumption Approximate | | +| | measurement | | +| | (mA)** | | ++============+============================+============================+ +| | Normal Mode | Standby Mode | ++------------+----------------------------+----------------------------+ +| AON timer | 53.01 | 4.59 | ++------------+----------------------------+----------------------------+ +| AON GPIO | 52.97 | 4.74 | ++------------+----------------------------+----------------------------+ +| RTC | 53.05 | 4.65 | ++------------+----------------------------+----------------------------+ + +Open example in “File” -> “Examples” -> “AmebaPowerMode” -> +“DeepSleepMode”. + +|image01| + +| Next is setting up the system and entering the power mode. Please refer to the following steps for entering Deep Sleep mode. +| Step 1. Set up the “WAKEUP_SOURCE”, AON timer: 0; AON GPIO: 1; RTC: 2. +| Step 2. Set up the wake-up source setting. There are 3 wake-up sources, each one has its own settings. +| For AON timer, at section ”#if (WAKEUP_SOURCE == 0)”, set value to “CLOCK” and “SLEEP_DURATION”. “CLOCK” can be 4MHz or 100kHz. “SLEEP_DURATION” unit is in seconds. +| For AON GPIO, at section “#elif (WAKEUP_SOURCE == 1)”, set value to “WAKUPE_SETTING”. “WAKUPE_SETTING” in this case is the Pin number, that can be 21 or 22. The GPIO pin is set to active high, please refer to the following connection. + +|image02| + +| For RTC, at section “#elif (WAKEUP_SOURCE == 2)”, set value to “ALARM_DAY”, “ALARM_HOUR”, “ALARM_MIN”, or “ALARM_SEC”. All alarm values set the duration of RTC wake-up. The range is “1day, 0h, 0m, 0s” to “365day, 23h, 59min, 59s”. +| Step 3. Start the Deep Sleep mode. There is only 1 optional setting for this step. When the wake-up source is set to RTC, use “PowerMode.start(1970, 1, 1, 0, 0, 0);” to replace “PowerMode.start();” for setting the start time. (Default is 1970.1.1 00:00:00). + +|image03| + +| To wake up, all timers will automatically wake up when the duration is finished, all GPIO pins must active high by pressing the push button. +| The correct boot, enter deep sleep, and reboot cycle will be same as following picture. + +|image04| + +.. |image01| image:: ../../_static/Example_Guides/PowerMode/Deep_Sleep_Mode/image01.png + :width: 561 px + :height: 810 px + +.. |image02| image:: ../../_static/Example_Guides/PowerMode/Deep_Sleep_Mode/image02.png + :width: 621 px + :height: 517 px + +.. |image03| image:: ../../_static/Example_Guides/PowerMode/Deep_Sleep_Mode/image03.png + :width: 567 px + :height: 502 px + +.. |image04| image:: ../../_static/Example_Guides/PowerMode/Deep_Sleep_Mode/image04.png + :width: 494 px + :height: 1002 px diff --git a/source/Example_Guides/PowerMode/Standby Mode.rst b/source/Example_Guides/PowerMode/Standby Mode.rst new file mode 100644 index 0000000..b9d78d8 --- /dev/null +++ b/source/Example_Guides/PowerMode/Standby Mode.rst @@ -0,0 +1,125 @@ +Standby Mode +============ + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +- Optional: Push button x 1 + +- Optional: Register 220 ohms x 1 + +- Optional: USB to ttl serial cable x 1 + +Example +------- + +In this example, the development board will demo the Standby Mode for power save. There are 6 wake-up sources The system will count down 5s then go to Stand By mode. Upon the wake-up source being tiggered, the system will be reboot and wake up again. + +The module and board power consumption report under Standby mode are listed in these two tables below. + +**RTL8735B module power consumption test results** + ++-----------------------+----------------------------------------------+ +| **Wake-up source** | **Module power consumption** | +| | | +| | **(uA)** | ++=======================+==============================================+ +| | Stand By Mode (measure at 3V3) | ++-----------------------+----------------------------------------------+ +| AON timer | 41.22 | ++-----------------------+----------------------------------------------+ +| AON GPIO | 41.28 | ++-----------------------+----------------------------------------------+ +| RTC | 41.46 | ++-----------------------+----------------------------------------------+ +| PON GPIO | 41.07 | ++-----------------------+----------------------------------------------+ +| UART/Serial1 | 41.32 | ++-----------------------+----------------------------------------------+ +| Gtimer0 | 41.48 | ++-----------------------+----------------------------------------------+ + +**AMB82-MINI board Power Consumption** + ++-----------------------+-----------------------+----------------------+ +| **Wake-up source** | **Development board | +| | power consumption** | +| | | +| | **Approximate | +| | measurement (mA)** | ++=======================+=======================+======================+ +| | Normal Mode | Standby Mode | ++-----------------------+-----------------------+----------------------+ +| AON timer | 53.15 | 4.79 | ++-----------------------+-----------------------+----------------------+ +| AON GPIO | 53.12 | 4.81 | ++-----------------------+-----------------------+----------------------+ +| RTC | 53.11 | 4.75 | ++-----------------------+-----------------------+----------------------+ +| PON GPIO | 55.09 | 4.87 | ++-----------------------+-----------------------+----------------------+ +| UART/Serial1 | 55.61 | 4.79 | ++-----------------------+-----------------------+----------------------+ +| Gtimer0 | 55.59 | 4.83 | ++-----------------------+-----------------------+----------------------+ + +Open example in “File” -> “Examples” -> “AmebaPowerMode” -> “StandbyMode”. + +|Image01| + +| Next is setting up the system and entering the power mode. Please refer to the following steps for entering Standby mode. +| Step 1. Set up the “WAKEUP_SOURCE”, AON timer: 0; AON GPIO: 1; RTC: 2, PON GPIO: 3, UART/Serial1: 4, Gtimer0: 5. +| Step 2. Set up the wake-up source setting. There are 6 wake-up sources, each one has its own settings. +| For AON timer, at section ”#if (WAKEUP_SOURCE == 0)”, set value to “CLOCK” and “SLEEP_DURATION”. “CLOCK” can be 4MHz or 100kHz. “SLEEP_DURATION” unit is in seconds. +| For AON GPIO, at section “#elif (WAKEUP_SOURCE == 1)”, set value to “WAKUPE_SETTING”. “WAKUPE_SETTING” in this case is the Pin number, that can be 21 or 22. The GPIO pin is set to active high, please refer to the following connection. + +|image02| + +| For RTC, at section “#elif (WAKEUP_SOURCE == 2)”, set value to “ALARM_DAY”, “ALARM_HOUR”, “ALARM_MIN”, or “ALARM_SEC”. All alarm values set the duration of RTC wake-up. The range is “1day, 0h, 0m, 0s” to “365day, 23h, 59min, 59s”. +| For PON GPIO, at section “#elif (WAKEUP_SOURCE == 3)”, set value to “WAKUPE_SETTING”. “WAKUPE_SETTING” in this case is the Pin number, that can be 0 to 11. The GPIO pin is set to active high, please refer to the following connection. + +|image03| + +For UART/Serial1, there is no setting required. However, USB to ttl serial cable Tx(green) and Rx(white) pin needs to connect to Serial1 Rx and Tx pin. Refer to the following connection. (Power 5V/3.3V Red, Ground Black) + +|image04| + +| For Gtimer0, at section “#elif (WAKEUP_SOURCE == 5)”, set value to “SLEEP_DURATION”. “SLEEP_DURATION” is the timer sleep duration in seconds. +| Step 3. Start the Standby mode. There is only 1 optional setting for this step. When the wake-up source is set to RTC, use “PowerMode.start(1970, 1, 1, 0, 0, 0);” to replace “PowerMode.start();” for setting the start time. (Default is 1970.1.1 00:00:00). + +|image05| + +| To wake up, all timers will automatically wake up when the duration is finished, all GPIO pins must active high by pressing the push button, UART needs to give input by Serial1 though USB-ttl cable. +| The correct boot, enter Standby, and reboot cycle will be same as following picture. + +|image06| + +.. |image01| image:: ../../_static/Example_Guides/PowerMode/Standby_Mode/image01.png + :width: 598 px + :height: 884 px + +.. |image02| image:: ../../_static/Example_Guides/PowerMode/Standby_Mode/image02.png + :width: 621 px + :height: 517 px + +.. |image03| image:: ../../_static/Example_Guides/PowerMode/Standby_Mode/image03.png + :width: 741 px + :height: 619 px + +.. |image04| image:: ../../_static/Example_Guides/PowerMode/Standby_Mode/image04.png + :width: 511 px + :height: 706 px + +.. |image05| image:: ../../_static/Example_Guides/PowerMode/Standby_Mode/image05.png + :width: 568 px + :height: 679 px + +.. |image06| image:: ../../_static/Example_Guides/PowerMode/Standby_Mode/image06.png + :width: 604 px + :height: 1003 px \ No newline at end of file diff --git a/source/Example_Guides/PowerMode/index.rst b/source/Example_Guides/PowerMode/index.rst new file mode 100644 index 0000000..87e2e86 --- /dev/null +++ b/source/Example_Guides/PowerMode/index.rst @@ -0,0 +1,8 @@ +PowerMode +========= + +.. toctree:: + :maxdepth: 1 + + Deep Sleep Mode + Standby Mode diff --git a/source/Example_Guides/RTC/Simple RTC Alarm.rst b/source/Example_Guides/RTC/Simple RTC Alarm.rst new file mode 100644 index 0000000..70291cc --- /dev/null +++ b/source/Example_Guides/RTC/Simple RTC Alarm.rst @@ -0,0 +1,34 @@ +Simple RTC Alarm +================ + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +Example +------- + +This example demonstrates how to use the RTC library methods to create a RTC Alarm, so that to do some tasks when an alarm is matched. In particular, the RTC time is set at 16:00:00 and an alarm at 16:00:10. When the time matches, “Alarm Match” information will be printed on the serial monitor. + +First, select the correct Ameba development board from the Arduino IDE: “Tools” -> “Board”. + +Then open the ” RTCAlarm ” example from: “File” -> “Examples” -> “RTC” -> “Simple_RTC_Alarm”: + +|image01| + +In the example, the RTC time is set at 16:00:00 and an alarm is set at 16:00:10. Upon successfully upload the sample code and press the reset button. When the alarm time (10 seconds) is reached the attached interrupt function will print the following information: “Alarm Matched!” showing in this figure below. + +|image02| + +.. |image01| image:: ../../_static/Example_Guides/RTC/Simple_RTC_Alarm/image01.png + :width: 602 px + :height: 833 px + +.. |image02| image:: ../../_static/Example_Guides/RTC/Simple_RTC_Alarm/image02.png + :width: 598 px + :height: 318 px diff --git a/source/Example_Guides/RTC/Simple RTC.rst b/source/Example_Guides/RTC/Simple RTC.rst new file mode 100644 index 0000000..daf8432 --- /dev/null +++ b/source/Example_Guides/RTC/Simple RTC.rst @@ -0,0 +1,40 @@ +Simple RTC +========== + +.. contents:: + :local: + :depth: 2 + +Materials +--------- + +- `AMB82-mini `_ x 1 + +Example +------- + +This example demonstrates how to use the RTC library methods. This function describes how to use the RTC API. The RTC function is implemented by an independent BCD timer/counter. + +Select the correct Ameba development board from the Arduino IDE: “Tools” -> “Board”. + +Then open the “RTC” example from: “File” -> “Examples” -> “AmebaRTC” -> “Simple_RTC”: + +|image01| + +Upon successfully upload the sample code and press the reset button, this example will print out time information since the user initialized time every second in the Serial Monitor. + +|image02| + +Code Reference +-------------- + +| [1] Simple RTC example from Arduino Tutorials: +| https://www.arduino.cc/en/Tutorial/SimpleRTC + +.. |image01| image:: ../../_static/Example_Guides/RTC/Simple_RTC/image01.png + :width: 602 px + :height: 833 px + +.. |image02| image:: ../../_static/Example_Guides/RTC/Simple_RTC/image02.png + :width: 597 px + :height: 325 px \ No newline at end of file diff --git a/source/Example_Guides/RTC/index.rst b/source/Example_Guides/RTC/index.rst new file mode 100644 index 0000000..ecb95e6 --- /dev/null +++ b/source/Example_Guides/RTC/index.rst @@ -0,0 +1,9 @@ +RTC +=== + +.. toctree:: + :maxdepth: 1 + + Simple RTC + Simple RTC Alarm + \ No newline at end of file diff --git a/source/Example_Guides/SPI/LCD Screen ILI9341 TFT.rst b/source/Example_Guides/SPI/LCD Screen ILI9341 TFT.rst new file mode 100644 index 0000000..3896175 --- /dev/null +++ b/source/Example_Guides/SPI/LCD Screen ILI9341 TFT.rst @@ -0,0 +1,168 @@ +LCD Screen ILI9341 TFT +====================== + +.. contents:: + :local: + :depth: 2 + +If you are not familiar with SPI, please read `Introduction to +SPI `_ first. + +Materials +--------- + +- `AMB82-mini `_ x 1 + +- ILI9341 TFT LCD with SPI interface x 1 + +Example +------- + +We have tested the following two models of ILI9341 TFT LCD with SPI interface: + +- Adafruit 2.8″ TFT LCD (with touch screen) + + - https://www.adafruit.com/products/1651 + + - https://learn.adafruit.com/adafruit-2-8-tft-touch-shield-v2?view=all + +- QVGA 2.2″ TFT LCD + + - http://www.lcdwiki.com/2.2inch_SPI_Module_ILI9341_SKU:MSP2202 + +Common pins in ILI9341 TFT LCD with SPI interface: + +- MOSI: Standard SPI Pin + +- MISO: Standard SPI Pin + +- SLK: Standard SPI Pin + +- CS: Standard SPI Pin + +- RESET: Used to reboot LCD. + +- D/C: Data/Command. When it is at LOW, the signal transmitted are + commands, otherwise the data transmitted are data. + +- LED (or BL): Adapt the screen backlight. Can be controlled by PWM or + connected to VCC for 100% backlight. + +- VCC: Connected to 3V or 5V, depends on its spec. + +- GND: Connected to GND. + +**AMB82 MINI and QVGA TFT LCD Wiring Diagram:** + +|image01| + +**AMB82 MINI and Adafruit 2.8” TFT LCD touch shield:** + +|image02| + +Please note that this shield model enables the backlight by default and pin 8 is not for backlight, and the VCC should be connected to 5V. + +Open the example, “File” -> “Examples” -> “AmebaSPI” -> “LCD_Screen_ILI9341_TFT” + +|image03| + +| Compile and upload to Ameba, then press the reset button. +| Then you can see some display tests appear on the LCD screen, such as displaying different colors, drawing vertical and horizontal lines, drawing circles, etc.… + +|image04| + +Besides, it can also display any user images based on the screen size. Using the online Image converting tool `here `__ that supports input images in png, .jpg and .gif ad output as .c file. Upon converting is done, place the .c file in our template Amebalogo.h file and upload the code again. + +|image06| + +|image07| + +Code Reference +-------------- + +- |  **RGB 16-bit** + | ILI9341 uses RGB 16-bit to display colors. Different from RGB + 24-bit, it uses 5 bits for red, 6 bits for green, 5 bits for blue. + For example, the RGB 24-bit representation of sky blue is 0x87CEFF, + that is in binary: + + - Red: 0x87 = B10000111 + + - Green: 0xCE = B11001110 + + - Blue: 0xFF = B11111111 + +.. + + and converted to RGB 16-bit: + +- Red: B10000 + +- Green: B110011 + +- Blue: B11111 + +.. + + Then concatenate them, which forms B1000011001111111 = 0x867F + +- **Drawing of ILI9341** + + - First you must specify the range of the rectangle to draw, then + pass the 2-byte RGB 16-bit color to ILI9341 corresponding to each + pixel one by one, in this way ILI9341 fills each color to each + pixel. + + - You still must specify the drawing range even though the range + covers only one pixel. + + - From the rules we mentioned above, we can conclude that drawing + vertical or horizontal lines are faster than diagonal lines. + +- **Printing text on ILI9341** + + - In our API, each character is 5x7 but each character is printed to + size 6x8 (its right side and below are left blank), so as to + separate from next character. For example, the character “A”: + + |image05| + + - The font size represents the dot size. For example, if the font + size is 2, each dot in the character is a 2x2 rectangle + +- **Screen rotation** + + - ILI9341 provides 0, 90, 180, 270 degrees screen rotation. + + - If the original width is 240 and original height is 320, when the + screen rotates 90 degrees, the width becomes 320 and the height + becomes 240. + +.. |image01| image:: ../../_static/Example_Guides/SPI/LCD_Screen_ILI9341_TFT/image01.png + :width: 1020 px + :height: 593 px + +.. |image02| image:: ../../_static/Example_Guides/SPI/LCD_Screen_ILI9341_TFT/image02.png + :width: 957 px + :height: 642 px + +.. |image03| image:: ../../_static/Example_Guides/SPI/LCD_Screen_ILI9341_TFT/image03.png + :width: 606 px + :height: 707 px + +.. |image04| image:: ../../_static/Example_Guides/SPI/LCD_Screen_ILI9341_TFT/image04.png + :width: 938 px + :height: 300 px + +.. |image05| image:: ../../_static/Example_Guides/SPI/LCD_Screen_ILI9341_TFT/image05.png + :width: 193 px + :height: 258 px + +.. |image06| image:: ../../_static/Example_Guides/SPI/LCD_Screen_ILI9341_TFT/image06.png + :width: 960 px + :height: 501 px + +.. |image07| image:: ../../_static/Example_Guides/SPI/LCD_Screen_ILI9341_TFT/image07.png + :width: 634 px + :height: 906 px + diff --git a/source/Example_Guides/SPI/index.rst b/source/Example_Guides/SPI/index.rst new file mode 100644 index 0000000..0a751b6 --- /dev/null +++ b/source/Example_Guides/SPI/index.rst @@ -0,0 +1,8 @@ +SPI +=== + +.. toctree:: + :maxdepth: 1 + + LCD Screen ILI9341 TFT + \ No newline at end of file diff --git a/source/Example_Guides/index.rst b/source/Example_Guides/index.rst index fa2855f..f581d35 100644 --- a/source/Example_Guides/index.rst +++ b/source/Example_Guides/index.rst @@ -6,9 +6,17 @@ Example Guides Basic/index Flash Memory/index + GPIO/index + GTimer/index + MQTT/index Multimedia/index QR Code Scanner/index Neural Network/index + NTP/index OTA/index + PowerMode/index + PWM/index + RTC/index + SPI/index USB/index Watchdog/index