2018年5月26日土曜日

Demonstrating Block Chain with a set of micro:bits using radio

Currently, blaockchain, which is the basic technology of crypto currencies, attracts attention. Below is an example that lets us easily learn the basics of Bclockchain technology using micro:bit.


micro:bit radio-blockchain

https://makecode.microbit.org/projects/micro-coin

Although this is not practical, it is convenient for us to experience the following basic technologies:
  • Structure of the block which is an element of blockchain, especially storage of hash value on previous block information
  • Broadcasting of newly added block information which is required after new crypto currency is obtained
  • How to add a new block to the chain
  • Mechanism to maintain only one consistent block chain

The following experiments were conducted basically in accordance with the above url. However, we use six micro:bits under the wireless network.  In addition, I have created an original method to display the number of coins on the LED.  Next figure illustrates the experiment.


In the figure below, the micro:bit in the lower left corner got a new coin. In the real world of crypto currency,  in order to obtain new coins,  it is necessary to solve certain problems (that is,  proof of work).  However,  here,  for the sake of simplicity,  it is possible to obtain a coin stochastically by using random number generated when macro:bit is shaken.  The micro:bit that got the coin creates a new block,  adds it to the chain,  and broadcasts it to other micro:bits.  In the figure,  one flashing LED means broadcast,  and two flashing LEDs indicate that the micro:bit  has received it.

One micro:bit that obtained a coin broadcasts its information

The following figure shows the number of coins currently held by each node (micro:bit). You can display this information by pressing button A on each node. Each of the three nodes has one coin and the other one node holds three coins.

the number of coins that have been obtained by each micro:bit 

Next, we verify that the block chain known to each node is only one legitimate one. As a simple way to show it, the length of the block chain known to each node is displayed. Press button B on each node to display it. Here, all nodes indicate 6 (= 1 + 1 + 1 + 3). This is a proof of integrity that there is only one legitimate block chain.


the length of the block chain each micro:bit can see (6 blocks)


The micro:bit program (blocked JavaScript) that realizes the above is shown in the figure below. In this, readio-blockchain for exchanging block information is used. It is published in the following URL:

https://makecode.microbit.org/pkg/microsoft/pxt-radio-blockchain

In addition, I created my own custom blocks to display on the LEDs the number of coins and the length of the chain.


micro:bit program that demonstrates  block chain

radio-blockchain components

custom JavaScript blocks for showing numbers on the LED

The above was done using 6 actual micro:bits. However, before that, you can also check the operation by simulation. This simulator works very well. As shown in the figure below, for example, you can simulate an operation to obtain coins by shaking micro:bit. Here, when you shake the microbits on the right side, the image of micro:bit is distorted, so you can get a sense of reality.


showing the number of coins in the simulation

shaking to get a coin in the simulation

2018年5月20日日曜日

Making custom blocks(with JavaScript) for micro:bit applications

This small article describes a feature of micro:bit visual block (with JavaScript). In particular, it is about user's block definition function. In the last article (No. 3), micro:bit was used as an indicator of pips of the dice. Dice is also commonly used in games and other applications.

Therefore it is convenient to have a custom block (user defined block) to display the dice 's eyes on the LED. To exceed the beginner level, it is essential to use this custom block function. A simple example is shown below. 


In the following, the function "show_pips_on_dice" was defined as a custom block. The argument denotes the number of pips of the dice. Every time you press button A, the eyes of the dice are displayed in ascending order. Thanks to the custom block, you can write it concisely like this.

Using custom block for displaying pips on a dice

The setting of this custom block is performed as shown below. Define this function "show_pips_on_dice (n: number)" in the namespace "custom". Then you can use (call) this function as a block from the menu "Custom". This definition content is stored in a file called "custom.ts".

Definition of a custom block for displaying pips on a dice


2018年5月14日月曜日

Cooperation between micro:bit and MIT App Inventor (No.3)

In the last article (No.2), communication between micro:bit and Android smartphone was done with Bluetooth UART service (serial over Bluetooth). I will also use this UART this time, but I would like to consider a simple example including NFC which is a short range wireless communication other than Bluetooth.

The figure below shows the contents. Prepared here a big toy dice. We prepared six NFC tags on which the number of eyes on each side are written, and incorporated them on each surface of the dice. Flip over the Android terminal and touch the dice on the back of it. Then the number of eyes on the opposite side of the touched surface is read. The number of eyes read is sent to micro:bit by UART communication. Pressing the micro:bit buttonA will make it receive that information and display the number of eyes on the micro:bit LED.



please see also the following youtube:
https://youtu.be/aOb69nweq3c

Using NFC in addition to BLE UART

The Android program was created using MIT App Inventor. After reading NFC tag information (number of eyes of dice), it will send the number of eyes on the opposite side of that face to micro:bit using UART. At the same time, an image corresponding to the number of eyes should be displayed on Android's screen.

Android program (reading NFC tags and sending with UART)

On the micro:bit side, pressing buttonA gets the number of eyes sent from Android, so we just display it on the LED. The function "show_spots_on_dice" is defined with JavaSript as a custom block. In this example, since we received 4 as the number of eyes, the four outer corners of the LED are lit.


micro:bit program to receive the pips of a dice and to display it on the LED board

2018年5月12日土曜日

Cooperation between micro:bit and MIT App Inventor with Eddystone signals (No.2)

In the last article (No. 1), a program (with microbit JavaScript block editor) that sends Eddystone signals (either Eddystone-UID or Eddystone-URL) and a program that receives it with Android (by MIT App Inventor) were presented.

In this article, Eddystone-URL data that should be adversised by maicro:bit is updated from Android side. To do that, I use the Bluetooth UART service (serial over Bluetooth). Overview of the mechanism is as shown in the figure below.




Let's see the operation of Android. (a) is the initial state. In (b) we are sending a new URL to the micro bit in response to a request. In (c), the URL currently stored in microbit should be sent back for confirmation.



URL information updating

Next, I will examine the source program briefly. The figure below is a micro:bit program. When you press button B, URL information should be received from Android side. Also, if you touch pin P0, it will send the current URL to Android. Press button A to advetise the URL.





The main parts of the Android program created with MIT App Inventor are shown below. We are communicating using BLE's UART, but in App Inventor we can use BLE extensions, which makes it very concise. However, in addition to this, connection settings with a standard BLE device, decoding of URL information, etc. are also necessary.



Main part of BLE UART communication with MIT App Inventor

Finally, here is the result of displaying the web page of the adverrtised URL in another application. For example, in the above figure, we setup 6 characters "RwaMqL". This is the actual URL with the header "http://goo.gl/" appended. However, this is a shortened version of the original URL. That's because of the limitation of the number of characters that can be advertised.

The shortened URL "RwaMqL" denotes Dept. of Mathematics, Hokkaido Univ.



2018年5月9日水曜日

Cooperation between micro:bit and MIT App Inventor with Eddystone signals (No.1)


Let's try to collaborate between micro:bit which is currently drawing attention and MIT App Inventor for Android. As one of them, we exchange Eddystone signals. There are several signal configurations of Eddystone, but here we deal with Eddystone-UID and Eddystone-URL among them.

Micro:bit (advertiser) and Android (receiver)


Let's perform the demonstration and watch it.
As a Microbit program, we made it possible to advertise these two types of Eddystone signals.  First, when you press micro: bit button A, it advertises the current pitch (inclination to the horizontal plane) and temperature. In the figure below, you can see that they are being received on the Android screen. That is, at the present time, the pitch of micro: bit is 30 degrees, and the temperature is found to be 26 degrees Celsius.

Pressing buttonA on the Micro:bit makes it advertise two kinds of data

Next, when pressing the micro:bit button B, a certain URL is advertised. On the screen of Android, the received contents are displayed.
Pressing buttonB on the Micro:bit makes it advertise an url of a web page


And soon, the web page for that URL was automatically displayed. In this case, it is a web page about the Akita dogs which became more famous for being given to famous Russian ice figure skater Miss Zagitova (Алина Ильназовна Загитова).
In this case, cheerful “Japanese Akita Dogs” web page is illustrated


Let's see these source programs. The following figure is a micro:bit advertising program. By pressing button A or button B you can issue either Eddysotne-UID or Eddystone-URL.


Eddystone advertising program (micro:bit)

Next is the Android program that receives Eddystone. This is made with MIT App Inventor only. It uses the extensions function for BLE (Bluetooth Low Energy), so it's very easy to write. However, the figure below shows only the essential part. By this alone, it is possible to directly acquire the content of the received data advertised. Thereafter, for example, it is necessary to decode the received URL data and convert it into a character string. It is also necessary to pass it to the Web viewer. All of them can also be written with MIT App Inventor.
Main part of Eddystone receiving program (MIT App Inventor)


please read this related article

Thanks
FoYo