ラベル microbit の投稿を表示しています。 すべての投稿を表示
ラベル microbit の投稿を表示しています。 すべての投稿を表示

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月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