2018年10月30日星期二

UART OBLOQ IoT Module Tutorial 3: Get Firmware version

In this tutorial we will check how to get the firmware version that is running on the UART OBLOQ.

As we have covered in this introductory post, OBLOQ is based on the famous ESP8266. Since we interact with OBLOQ with serial commands, it means that the ESP8266 microcontroller is running a firmware that is able to interpret those commands and act accordingly.

This means that this firmware may change over time, so it’s useful to have a way of checking the version that is running in our device, so we know which commands are available.

In order to interact with the OBLOQ, we will use a serial to USB converter and the Arduino IDE serial monitor. Please check in this previous tutorial the wiring needed between the two devices and how to use the serial monitor to interact with it.

The command

The command needed to retrieve the firmware version is very simple, pretty much like we did in the previous tutorial for pinging the device. So basically we just need to send the command below:

|1|2|
Figure 1 shows the Arduino IDE serial monitor before sending this command. Don’t forget to set “Carriage return” in the first dropdown at the bottom of the serial monitor. Also make sure to set the baud rate to 9600.
Figure 1 – Sending the UART OBLOQ command to retrieve the firmware version.




























Upon sending the command, you should receive the OBLOQ answer with the currently running firmware version, in the following format:

|1|2|version|
You can check the expected result in figure 2. As can be seen, my device is running version 3.0 of the firmware.
Figure 2 – Printing the firmware version of OBLOQ.










UART OBLOQ IoT Module Tutorial 1: a Quick Look in Obloq

The UART OBLOQ is an Internet of Things module module from DFRobot. It is based on the famous ESP8266 WiFi enabled SoC and exposes a command based interface over Serial. The device is shown in figure 1.
Figure 1 – UART OBLOQ.


























So, in other words, the ESP8266 of the UART OBLOQ is running a custom firmware that receives commands via serial and is able to interpret them and act accordingly. This firmware comes already flashed in the device, so we don’t need to flash it ourselves.

This means we can connect another microcontroller to the UART OBLOQ and offload from it the WiFi related functionalities. For example, we can develop an application in an Arduino board and then interact with the UART OBLOQ to send messages to remote applications over the Internet.

Currently, in version 3.0 of the UART OBLOQ firmware, we can use MQTT and HTTP as protocols to communicate with other devices and applications. Note however that, since the UART OBLOQ is based on the ESP8266, it is possible that, in future firmware versions, more communication protocols can be implemented.

The UART OBLOQ can operate with a supply voltage between 3.3 V and 5 V and a current of less than 240 mA [2]. This means that we need to use a power supply capable of providing a considerable amount of current for it to operate correctly.

It is a relatively compact device, with the dimensions of 35 mm x 32 mm and a weight of 16 g.

The device already includes an antenna, which means the WiFi functionalities can be used out of the box without the need for additional connections or soldering.

The UART OBLOQ exposes a minimalist interface with only 4 pins. Two of them are for power supply (GND and VCC), and the other two are the Rx and Tx pins of the Serial interface.

The device operates with a baud rate of 9600 [1], so this needs to be taken into consideration when establishing a serial connection to it.

Additional Resources


Product page
Product WiKi
Sample code
Arduino library
Firmware page


2018年10月28日星期日

Microbit Project 12:Escape the maze

Micro:bit is trapped inside the maze with a time bomb! Poor micro:bit cannot move by itself. However, it sends out signal through the LED panel to lead the way. We need to help him escape the maze before the bomb explodes!
Components needed

1× RGB LED strip
1× USB cable

Hardware Connection

Connect the RGB LED strip to P1.















Program
STEP1: First, we will need to let micro:bit randomly generate some movements to simulate the maze. Also, micro:bit should be able to know which way it tilts. If the two directions match, 1 point will be added to the final score, which means that we are 1 step closer from escaping the maze. 

The following flow chart may be helpful in explaining how the program works.




































We will use number 0 ~ 3 to represent four target directions respectively. The function "pick random" under “Math” help us to get a random number from 0 ~ 3.





STEP2: Show the arrow image on the LED panel. The arrow should correspond to the randomly generated target direction we got from above. Again, the “if-else” function will be our choice to do the job.




















STEP3:  Use the “on xxx gesture” function under “input” to sense which direction the micro: bit tilts. The number inside the function loop represents four different directions. 






































TEP4:  Put everything we mentioned above inside an “if-then” loop to compare if the two directions match. Also, don't forget the “forever” loop to keep the game always on going.































Note: it will be helpful to add a “While” function inside the loop, so as to avoid identical directions appear in a row.

STEP5: it's the time to add the bomb. The bomb will start ticking as soon as the game begins. Also, we will use the RGB LED strip to simulate the fuse. With the time running, the LEDs on the fuse will go off one after another in a steady pace. If micro:bit cannot make it to escape the maze before the fuse burning out, the game is over. 

The flow chart below shows how to set the LED go one by one with the time go



































We will be explaining the functions that we need to achieve it.

Note: Micro: bit needs extra time to process the data, so the clock will run a bit slower than what we set.

















The following program is used to set how many LED lights up.









STEP6: A scoring mechanism will be needed to tell us whether we made it to escape. The following flow chat may give you an idea of how it works..


































Remember to reset the score at the beginning of the program.









STEP7:  Now, integrate the scoring function to the main program.
































STEP8:Here is how the final program looks like

















Exercise

Try to make the clock tick faster to increase the difficulty;

Program the LEDs to make them flash at a pace based on the remaining time;
Unintuitive challenge! Set different directions in pairs and see if you can still finish the game. For example, you will need to tile top to match a left arrow, tile bottom to match a right arrow.









Microbit Project 11: Remote Doorbell

For those who have a doorbell in their homes, it may be quite a common issue that sometimes the ring is not loud enough to travel over rooms. To solve this problem, a wireless indicator may be helpful. In the chapter, we will learn how to make the doorbell to control a remote LED that we can carry around.

Component list

micro:bit
Boson Expansion board
1× LED module
1× motion sensor module
1× knob module
1× USB cable

Connection

We will need two micro:bit in this project, one is attached to the door bell and sends out message (transmitting end), the other receives the signal and controls the LED indicator (receiving end). The micro:bits communicates over radio.















Connection diagram of micro:bit transmitter:





















Connection diagram of micro: bit receiver:



















Program
Task1: program for the transmitter

STEP1: We have been quite familiar with the button module and the motion sensor, however, how can we send out their status through over the radio? To achieve this, we will learn how exactly the radio works in the following session.

The "Radio" function can be found on the left side of the MakeCode window.







































We need to first understand the following 3 most commonly used functions under “Radio”:
set group:





Function description: There are a total of 255 different radio channels. The transmitter and the receiver should be set in the same group to communicate. send out number:





Function description: send out a number over radio. on radio received:






Function description: Upon a number is received, it will execute the program inside the “on radio received” loop.
We will also need to program the receiver to make the corresponding reaction based on the received number.
Notice: the variable "receivedNumber" inside the “on radio received” function represents the received number.

STEP2: After knowing how to use the radio function, it is the time to use input modules to trigger the radio signal. To make it a bit more challenging, we will try to program the micro:bit send out a message when someone rings the bell, and send out another message when there is just someone passing by. To achieve this, we will need the button module and a motion sensor. The flow chart below gives you an idea of how to write the program.















STEP3: Put the function blocks together. The complete program will be look like as following.










Task2: program the receiver

STEP1: The receiver is able to execute different action based on the received signal. The flow chart below will help you in building the program.
























STEP3: Put the function blocks together. The complete program will be look like as following.
























Exercise

Add a “Please wait” notice to the doorbell when someone rings the bel

Microbit Project 10: DJ PANEL

Components needed

Main control board of micro:bit
Expansion board of micro:bit
1× Rainbow LED strip
1× knob module
1× USB cable

Hardware Connection

Connect the knob module to the interface P1 of expansion board;
Connect the rainbow LED strip to the interface P2 of expansion board.




















Program
Functions: Realize the music performance with the LED strip when adjusting the rotation angle of the knob.

When the knob is turned by hand, the value of the P1 pin changes from 0 to 1023 and is divided into 8 small ranges, corresponding to one octave "Do ~ Do’" in the music and the number of changing LEDs of the the light strip.
The input value of P1SoundThe LED strip
0-128Do                          Light one LED
128-256ReLight two LEDs
256-384MeLight three LEDs
384-512FaLight four LEDs
512-640SoLight five LEDs
640-768LaLight six LEDs
768-996TiLight sever LEDs
996-1023Do'Light seven LEDs in red
STEP1:  the logic diagram to realize DJ bandstand.
















STEP2: the editing of logic statement "if", the operations go as follows.
























STEP3: judge the range of the input value of the knob(P1) and make the value correspond to the LED strip and sound. The following is the control procedures in the first area.







STEP4: Since there are only 7 LEDs, so "Do’" can be expressed in a different way in the 8th zone. 






STEP5:the final program











Exercises for improvement

Utilize the 5×5 LED matrix of the micro:bit. When different syllables are played, each of them should be correspondingly displayed by LEDs. Just have a try. 



2018年10月27日星期六

Microbit Project 9 : Electronic Stabilizer

Have you heard of the accelerometer? The accelerometer measures the acceleration along 3 direction and it is getting more popular in electronic gedgets. For example, you turn the phone or laptop 90 degrees, its page will follow your barycenter and turn 90 degrees automatically. This is a very human-centered design. In this lesson, we are going to simulate this function!

Components needed

Main control board of micro:bit
Expansion board of micro:bit
1× servo
1× USB cable   

Hardware Connection

Connect the servo to P0
























Program

Goal: Fix the servo on the micro:bit, servo will keep pointing upright regardless how we tile board.

Micro: bit detects the gesture automatically through the accelerometer. Gravitation force is also a form of acceleration ,and micro: bit can detect the gravitational force along X, Y, and Z directions, whereas X is along the left-right direction, Y is along the front-back direction, Z is perpendicular to the board and along the up-down direction.















The values of the X, Y, Z axes can be achieve from the function “acceleration” under "Input






























When the mainboard lays flat on the desktop, gravitational force goes along up-and-down direction, so that the values of X and Y axis are close to zero and the Z axis is around 1000 (mm / S2), which roughly equals to the gravitational acceleration.

When the board is tilted, the values of X and Y change. When it leans to the left, the value of X is negative or, conversely, positive.

So we can enable the servo to rotate a certain degrees in the opposite direction by detecting the leaning degrees of micro:bit to keep the pointer pointing upwards all the time. 

STEP1: When the board is tilted to the left, the gravity sensor will produce a negative output value along the X direction. We will rotate the micro: bit toward 0 degree to offset this angle and vice versa. Since the gravity sensor has a value between -2048 and 2048, and -500 to 500 is a range that can be effectively detected relatively, we can make the -500 ~ 500 correspond to 0 ~ 180 degrees of the servo through the “map 0”.















STEP2: Fix the servo and expansion board with double-sided tape so that the two remain relatively still. Noe that the orientation of the servo head needs to be the same as that of the USB port so that the gear shaft is perpendicular to the X axis and the degree of rotating of the servo is complementary to the degree of tilting of micro: bit.

Exercises for improvement
Try composing a compass using the electronic compass built into micro: bit.

Microbit Project 8: Colorful Light Strip

After the last lesson about the music box, have you found something more to be learned? Yes, in this lesson we will learn to make LED strip! Is it hard to wait? Let's get into the fantastic light world!

Components needed

Main control board of micro:bit
Expansion board of micro:bit
1× Rainbow LED strip
1× Sound sensor module
1× USB cable

Hardware Connection

Connect the RGB LED strip to the interface P0 of the expansion board

























Program

Task1: light the rainbow LED strip

Functions: when the program is burned to the micro:bit, you can control the rainbow LED strip with 7 colors.

STEP1: usually there is no instruction collection about the rainbow LED strip in the instruction area. To control the LED strip, the Neopixel needs to be called which can be found at the lowest part of the instruction area. Click "Add Package" and there appears the menu bar of it. The procedure for calling instruction: Advance ---- add package ---- neopixel. Click on neopixel to add the neopixel  module.





























































STEP2: usually, in the instructions controlling the rainbow LED strip, the pin of the micro:bit, the LED numbers and colors of the strip need to be decided first. The instruction needed here is as following:



After this, the scope of the LEDs needs to be determined. The instruction needed here is as following:




Then, the color ranges of the LED strip need to be decided. The instruction needed here is as following: 




The related instructions are as following: ( the parameters will be modified in use)

























STEP3: The pin P0 connected the strip contains 7 small LED lights. Set the color range of the strip as 1-360 (red - green - blue) to produce 7 colors. After adjusting the parameters, the final program is finished.




Task2: Turn on the rainbow lights successively

Functions : when the program is burn to the board, you can control the LEDs by lightening each one of them by every one second to show colorful effects.

STEP1: the instruction to treat the variable is required for lightening each one of them by every one second to control the number of LEDs to be lit. The procedure for calling instructions: Variables ---- Make a Variable, arbitrarily set the variable name (such as: the number of LEDs to be lit), and then click OK.
















































STEP2: "the number of LEDs to be lit" (also referred to as "a") is initially set as the variable is 0 (initially there is no light lit), then increase 1 while controlling the variable, the looping statement is needed here. When the "the number of LEDs to be lit" is less than 7 the instructions needed are as following to light the LEDs continuously.





































STEP3: When “the number of LEDs to be lit”(a) is less than 7, you can light (a) LEDs. After a delay of 1000ms, increase “the number of LEDs to be lit” to a+1. The flow chart is as following:






































STEP4: "the number of LEDs to be lit" (also referred to as "a") is initially set as 0. When “the number of LEDs to be lit”(a) is no more than 7, you can light (a) LEDs. After a delay of 1000ms, increase “the number of LEDs to be lit” to a+1. Then keep the cycle until “the number of LEDs to be lit” > 7, all LEDs go out. Keep one LED is lit by every one second.








Task3; rainbow LED strip controlled by a sound sensor

Functions: The LED strip is off initially, when there is sound, a LED of the strip is lit. When there is no sound, the LED keeps off.

STEP1: in this task, a sound sensor is needed. When there is sound, the sound sensor can detect it and light the LEDs. We have learnt how to use the sound sensor before, let's review how to call instructions. The procedure for calling the instruction is: Pins(advance) – analog read pin (p0), change P0 to P1
























STEP2: When the sound intensity > 40 is detected by the sound sensor and the number of lighted LEDs does not exceed 7, one more LED will be lit. Then the sound sensor continuously detect whether the sound intensity exceeds 40 or No.
The flow chart:






































STEP3:the final program