Difference between revisions of "IoT Tutorials"

From COINS Research Group
Jump to: navigation, search
(Created page with "==Tutorial Overview== ===Title === Introduction into Arduino and Internet Of Things Applications. === Author=== Abdelrahman Mahmoud ===Note=== For any suggestions/comments ab...")
 
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Tutorial Overview==
+
==Arduino IoT Workshop==
===Title ===
+
Introduction into Arduino and Internet Of Things Applications.
+
=== Author===
+
Abdelrahman Mahmoud
+
  
===Note===
+
* [http://wiki.coins-lab.org/index.php?title=ArduinoIoT Arduio-IoT Workshop]
For any suggestions/comments about this tutorial, please send an email to akoubaa@coins-lab.org / a.mahmoud1994@gmail.com
+
  
===Make sure you download:===
 
  
# Arduino 1.6.7 [https://www.arduino.cc/en/Main/Software version]
+
Learn ROS and get your ROS certificate by enrolling in the Udemy course ROS for Beginners: Basics, Motion and OpenCV.
  
*Download your OS version whether it is Windows/Linux/IOS
+
[[File:roscourse.png|link=https://www.udemy.com/ros-essentials/?couponCode=ROS1COINS]]
  
*Extract the zip file any where you want
+
Learn about ROS2: ROS Next Generation by enrolling in the Udemy course ROS2 How To: Discover Next Generation ROS
  
===Components===
+
[[File:ros2course2.png|link=https://www.udemy.com/ros2-how-to/?couponCode=ROS2COINS]]
 
+
*Arduiono UNO [https://www.arduino.cc/en/Main/ArduinoBoardUno boards]
+
 
+
===Description===
+
This tutorial will present some demo for the Arduino platform, how to read data from sensors, write data to sensors and send data to another arduino board through Xbee wireless communication.
+
 
+
====The Blink Program====
+
''Go to File -> Examples -> Basics -> Blink''
+
 
+
<tt>void setup() {
+
  // initialize digital pin 13 as an output.
+
  pinMode(13, OUTPUT);
+
}
+
+
// the loop function runs over and over again forever
+
void loop() {
+
  digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
+
  delay(1000);              // wait for a second
+
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
+
  delay(1000);              // wait for a second
+
}</tt>
+
 
+
''For the Receiver board:''
+
<tt>
+
void setup() {
+
  // initialize serial communication:
+
  Serial.begin(9600);
+
}
+
+
void loop() {
+
  // see if there's incoming serial data:
+
  if (Serial.available() > 0) {
+
  // It may differ how do you consider low and high
+
    if(Serial.read()==49)
+
    Serial.println("High");
+
    if(Serial.read()==48)
+
    Serial.println("Low");
+
  }
+
}</tt>
+
 
+
'''Description:''' It is very common when using XBees that you receive different data than what you are expecting. If you printed the received data when you run this code you will find out that the data is actually 48 and 49. The easiest way is to know the new range received and then convert this data to the original range/output that you are expecting.
+
'''Note:''' for the added space in the transmitter code refer to this [http://stackoverflow.com/questions/15993595/bad-data-received-from-arduino-serial-while-reading-from-analog-port link].
+
 
+
====The Python Script:====
+
<tt>import serial
+
import socket
+
+
from time import sleep
+
+
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=None)
+
UDP_IP = "127.0.0.1"
+
UDP_PORT = 5555
+
+
+
+
print "UDP target IP:", UDP_IP
+
print "UDP target port:", UDP_PORT
+
+
+
while True:
+
+
    data = ser.readline()
+
    sock = socket.socket(socket.AF_INET, # Internet
+
                    socket.SOCK_DGRAM) # UDP
+
    sock.sendto(data, (UDP_IP, UDP_PORT))
+
    print "Data:", data
+
+
    sleep(0.001)</tt>
+
 
+
===Important Notes ===
+
*Choose the same port number as the server has.
+
*Put the "Serial Select" switch in both shields to USB when you are uploading the program to the board then switch it to the other side -it may differ from a shield to another what the other side is called (XBEE, MICRO...etc)-.
+
===Executing step===
+
 
+
1.Run the UDPServerDemo.java file in the path src/org/psu/acmchapter/networking/udp/ using any program eclipse/netbeans/JCreator..etc
+
 
+
2. Run this command :
+
<code>
+
sudo chmod 777 /dev/ttyUSB0
+
</code>
+
 
+
To give the permission to the port you are using. '''Note:''' make sure you give the permission to the right port.
+
 
+
3.Upload the arduino programs to the arduino boards and make sure you picked the right Board and the right Serial Port.
+
 
+
4. run the python script by typing
+
<code> python filename.py</code>
+
 
+
'''Note'''
+
Type this command in a terminal after going to the right path where you keep the script file
+
 
+
5.Open the Server's console window to see the received data.
+

Latest revision as of 11:53, 10 August 2018

Arduino IoT Workshop


Learn ROS and get your ROS certificate by enrolling in the Udemy course ROS for Beginners: Basics, Motion and OpenCV.

Roscourse.png

Learn about ROS2: ROS Next Generation by enrolling in the Udemy course ROS2 How To: Discover Next Generation ROS

Ros2course2.png