loading

Introduction

This instructable is made for Bolt users who wish to interface the Bolt hardware unit with Arduino Uno or simply want to experiment with the Bolt UART.

Prerequisites

Access to Bolt IoT workshop and its successful completion is recommended as a few steps are omitted in the instructable assuming User has prior knowledge of working with basic Bolt hardware with respect to Control and Monitoring GPIO pins of Bolts and testing Basic Applications like LED glow etc on Bolt.

Bolt UART

The Bolt has a single UART interface and supports the following baud rates for serial communication.

1) 2400

2) 4800

3) 9600

4) 19200

To initiate the UART with required Baud rate you will need to call the following URL from your preferred Browser.

http://ip-address-of-bolt/serialBegin?baud=n

Where ip-address-of-bolt is the IP of the Bolt Unit on your local network and baud=n where "n" takes a value from 1 to 4 and it represents the respective baud rates as seen above.

For example if IP address of Bolt is 192.168.1.5 and you need to set 9600 baud rate the URL becomes:

http://192.168.1.5/serialBegin?baud=2

We will be using the same baud rate for this instructable.

Step 1: Send Values Over TX (Transmit Line) of Bolt UART

Once you have initialized the Baud rate on Bolt , you can now begin to send and receive date over the Bolt UART.

Serial Write Function (Transmit data)

To transmit data over the Serial port of Bolt you need to type the call the following URL from your browser:

http://ip-address-of-bolt/serialWrite?data=string-to-transmit

For example if we wish to transmit the String "hello":

http://192.168.1.5/serialWrite?data=hello

This command if executed correctly return a JSON object with key "success" set to "1" and key "value" set to "serial write successful"

Step 2: Receiving Data Over Rx (Receive Pin)

This step will allow you to read contents of the Receive buffer of the Bolt UART

Serial Read Function (Receive data)

To receive data over the Serial port of Bolt you need to type the call the following URL from your browser:

http://ip-address-of-bolt/serialRead

Example:

http://ip-address-of-bolt/serialRead

The command if executed correctly return a JSON object with key "success" set to "1" and key "value" set to "contents of Rx buffer"

If buffer is empty the reply for key "value" is set to "Receive buffer empty"

Serial Read "Till" (Receive data till required character)


To receive data over the Serial port of Bolt you need to type the call the following URL from your browser:

http://ip-address-of-bolt/serialRead?till=decimal-code-for-ascii-char 

Example: If you wish to read a the input buffer till you come across a Line Feed character or '\n' whose decimal code in the ASCII table is 10

http://192.168.1.5/serialRead?till=10

Case1: The command if executed correctly return a JSON object with key "success" set to "1" and key "value" set to "contents till last character before '\n' "

Case2: If '\n' isn't encountered in the buffer while reading all its contents will be held in key "value"

Case3: If buffer is empty the reply for key "value" is set to "Receive buffer empty"

Note: If the buffer isn't empty after '\n', then the next read command will contain the remaining contents of the buffer after '\n' but not including '\n'

To discard any extra / unnecessary values in the Receive buffer we have to flush it as shown in the Next Step.

Step 3: Flush Receive Buffer

To empty the contents of the Rx buffer of the Bolt UART you need to call the following URL:

http://ip-address-of-bolt/flushReceiver

Example:

http://192.168.1.5/flushReceiver

This will return a JSON object with "success" key set to "1" and "value" set to "Receive Buffer Flushed"

This command is particularly useful when you feel that the buffer may contain some extra or garbage data that needs to be cleared before acquiring relative data.

Step 4: Serial Read Command Response

An added functionality to Bolt is its ability to send a command to a system over the UART and if the response is received within 200ms it can fetch the same using a single command.

Serial Write and Read Function (serialWR)

To read response of a command you need to call the following URL from your Browser:

http://ip-address-of-bolt/serialWR?data=command&till=decimal-code-for-ascii-char

Example:

http://192.168.1.5/serialWR?data=hello&till=10

The reply for this command will be same as that of Step 2, only difference being that if the command response is empty then the key "value" will be an empty string => "" .

Note:Just as serialRead "till" is an optional parameter in the URL

Step 5: Interfacing Bolt With Arduino

In this step we will make the necessary hardware connections to setup serial communication between Arduino Deumilanove and Bolt.

This is pretty straight forward and you will need three male-to-male jumper cables for this step

1) Connect Tx pin of Bolt to Rx pin of Arduino .

2) Connect Rx pin of Bolt to Tx pin of Arduino .

and finally

3) Connect Gnd(ground) pin of Bolt to Gnd(ground) pin of Arduino .

Next you can upload the following code on Arduno to test Serial communications

void setup() {<br>  // put your setup code here, to run once:
  Serial.begin(9600); //Begin Serial at 9600
  Serial.setTimeout(50); //Timeout serial if readString is unavailable
}

void loop() {
  // put your main code here, to run repeatedly: <br>  String inString = "";  <br>  if (Serial.available() > 0) {
    // get incoming String
    inString = Serial.readString(); //Read input string from bolt
    Serial.print(inString); //Send same string back to bolt
  }
}

This is a Simple echo code which will reply back whatever the Arduino receive back to the Bolt.

Once you burn this code from on your Arduino call the following URL in your browser to test the system:

*assuming ip address of Bolt is 192.168.1.5

http://192.168.1.5/serialWR?data=hello

and you should get a JSON response with "success" key set to "1" and "value" key set to "hello".

Step 6: Test Screenshots.

After you finish interfacing we shall now check the responses and different commands learned previously.

In the First screenshot we only sent a String to Arduino saying "say hi to arduino"

The corresponding URL call for the Bolt being "http://192.168.2.16/serialWrite?data=say hi to arduino"

Next we read the response from Arduino which according to the code we uploaded in the previous step is just the same String we sent to it. The URL to do the same is "http://192.168.2.16/serialRead"

After that we send a string 12345 using the URL call "http://192.168.2.16/serialWrite?data=12345"

But now instead of reading the entire reply lets say we need to read the buffer only till we encounter the character "5" whose ASCII code in decimal is 53. The URL to do this becomes "http://192.168.2.16/serialRead?till=53"

Hence the response for the key "value" will be "1234" here 5 is omitted.

The next screenshot we test the serialWR command where we get immediately the echo to the data we write.The URL used here is "http://192.168.2.16/serialWR?data=12345"

After this is an example of Using serialWR till we encounter the letter "l" whose ASCII code in decimal is 108. The URL used here is "http://192.168.2.16/serialWrite?data=12345&till=108"

Hence the response for the key "value" will be "he" here l is omitted.

Now if we do a simple serialRead again using the URL call "http://192.168.2.16/serialRead" the response for the key "value" will be "lo" that is the remaining string after the first occurrence of the character "l".

<p>{&quot;success&quot;:&quot;1&quot;,&quot;value&quot;:&quot;serialWrite successful&quot;} </p><p>above statment also return when i remove my arduino from power supply </p><p>How can it possible?</p>

About This Instructable

2,180views

7favorites

License:

More by Datta_TECH:Interfacing Bolt With Arduino : Bolt UART 
Add instructable to: