User Tools

Site Tools


proiecte:sparrowv3-devicehub

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
proiecte:sparrowv3-devicehub [2015/10/06 00:36]
alex.marin [Real time monitoring with Devicehub]
proiecte:sparrowv3-devicehub [2015/10/08 01:01] (current)
alex.marin [SHT21 library]
Line 18: Line 18:
  
 <imgcaption sparrowv3 | Sparrow v3.2 Wireless Sensor Node>{{ :sparrowv3.png?800 | }}</imgcaption> <imgcaption sparrowv3 | Sparrow v3.2 Wireless Sensor Node>{{ :sparrowv3.png?800 | }}</imgcaption>
-==== Using Zigduino support in Arduino IDE ====+==== Adding the Sparrow Board to the Arduino IDE ====
  
-Zigduino is an Arduino compatible shield which has, as well as Sparrow v3, an Atmega128RFA1 micro controllerIn terms of software support, everything has been implemented in a branch forked from the Arduino official repository. We used the Zigduino support in order to program Sparrow v3 through Arduino IDE.+  - Download [[https://www.arduino.cc/en/Main/Software|Arduino]] 
 +  - Download and unzip the {{:sparrow_patch.zip|patch}} in a separate folder 
 +  - Locate the installation folder of Arduino on your drive (for Windows it's usually Program Files) 
 +  - Copy in **Arduino\hardware\arduino\cores** the contents of the folder **sparrow_patch\Arduino\hardware\arduino\cores\sparrow** 
 +  - Replace the file **Arduino\hardware\arduino\boards.txt** with **sparrow_patch\Arduino\hardware\arduino\boards.txt** 
 +  - Copy in **Arduino\hardware\arduino\variants** the folder named **sparrow** from **sparrow_patch\Arduino\hardware\arduino\variants** 
 +  - Restart the Arduino IDE
  
-One should follow the steps below for being able to program a Sparrow WSN using Arduino IDE:+After a successful patch, you should be able to select new board named Sparrow from the Tools>Board menu. Also select the appropriate COM port from the Tools>Port menu 
 +{{ :arduino.png?500 |}} 
 +You're all set up!
  
-1. Install Arduino IDEhttp://www.arduino.cc/en/Main/Software+=== Optional StepIf Your Nodes Don't Come With a Preinstalled Bootloader ===
  
-2Download Zigduino-1.0 archivehttps://github.com/logos-electromechanical/Zigduino-1.0+The binary will be installed on flash memory through a bootloaderMost probably Sparrow v3 will come with the bootloader already installed, but in case it won't or in case it somehow gets erased, one will need to install itYou can download the bootloader from {{::atmegaboot_168_atmega128rfa1.zip|here}}.
  
-3. Replace folder //Arduino\hardware\tools\avr// with //Zigduino-1.0-new-extension\hardware\tools\avr// 
- 
-4. Copy in //Arduino\hardware\arduino\cores// folder //Zigduino-1.0-new-extension\hardware\arduino\cores\zigduino// 
- 
-5. Replace file //Arduino\hardware\arduino\boards.txt// with //Zigduino-1.0-new-extension\hardware\arduino\boards.txt// 
- 
-6. Copy in //Arduino\hardware\arduino\variants// folders //zigduino _r1// and //zigduino_r2// from //Zigduino-1.0-new-extension\hardware\arduino\variants// 
- 
-Now you should see two new entries for Zigduino in //Tools->Boards// (Arduino IDE menu).  
- 
-NOTE: If Arduino IDE was already started, a restart will be needed. 
- 
-The binary will be installed on flash memory through a bootloader. Most probably Sparrow v3 will come with the bootloader already installed, but in case it won't or in case it somehow gets erased, one will need to install it. We used the bootloader described by the following address: //Zigduino-1.0-new-extension\hardware\arduino\bootloaders\atmega\ATmegaBOOT_168_atmega128rfa1.hex//. 
 In order to install the bootloader, a flash programmer will be needed (we used AVRISP mkII). We then installed AtmelStudio and used its built in Flash Programmer utility (//Tools->Device Programming// in AtmelStudio menu). In order to install the bootloader, a flash programmer will be needed (we used AVRISP mkII). We then installed AtmelStudio and used its built in Flash Programmer utility (//Tools->Device Programming// in AtmelStudio menu).
 +Fusebits: EXT 0XFE, HI 0xD0, LO 0xF7
  
 ===== Simple test program ===== ===== Simple test program =====
Line 51: Line 47:
 2. In //Tools->Programmer// choose //USBasp// 2. In //Tools->Programmer// choose //USBasp//
  
-3. In //Tools->Board// select //Zigduino_r1//+3. In //Tools->Board// select //Sparrow//
  
 4. From //Tools->Serial Port// choose the COM port to which the node was connected 4. From //Tools->Serial Port// choose the COM port to which the node was connected
Line 88: Line 84:
 ===== SHT21 library ===== ===== SHT21 library =====
  
-There is one more thing that we must take care of before we can start playing with our WSN monitoring project. We'll need a library for reading values from SHT21, our relative humidity and temperature sensor, connected to the micro controller through an I2C interface. You'll need to use the attached files (TODO insert link towards .h and .cpp) in the following way:+There is one more thing that we must take care of before we can start playing with our WSN monitoring project. We'll need a library for reading values from SHT21, our relative humidity and temperature sensor, connected to the micro controller through an I2C interface. You'll need to use the files stored in this {{:proiecte:sht21.zip| archive}} in the following way:
  
 1. In folder //Arduino\libraries// create a new folder, named //sht21// 1. In folder //Arduino\libraries// create a new folder, named //sht21//
  
-2. Copy the attached files in it+2. Copy the files from the attached archive in it
  
 After this it will be possible to import sht21.h header into a project, as you'll see below. After this it will be possible to import sht21.h header into a project, as you'll see below.
Line 106: Line 102:
  
 All non-gateway nodes are duty-cycling, in order to consume as less energy as possible. After each package sending, every non-gateway node enters in a deep sleep state, where all sensors and micro controller peripherals are deactivated. For waking up from these deep sleep state, MAC symbol counter is used together with SCNT_CMP1_vect interrupt. This interrupt is triggered when Symbol Counter Register has the same value as Symbol Counter Output Compare Register, the latter being previously initialized for the sleep period wanted. All non-gateway nodes are duty-cycling, in order to consume as less energy as possible. After each package sending, every non-gateway node enters in a deep sleep state, where all sensors and micro controller peripherals are deactivated. For waking up from these deep sleep state, MAC symbol counter is used together with SCNT_CMP1_vect interrupt. This interrupt is triggered when Symbol Counter Register has the same value as Symbol Counter Output Compare Register, the latter being previously initialized for the sleep period wanted.
 +
 +You can see below a representation of the topology we've used, followed by our source code. Multiple nodes are sending the data they've read from their sensors towards the gateway node, which further sends them through serial interface towards a Raspberry Pi board, on which a Devicehub mqtt script is running. The Raspberry Pi board may be connected to Internet either by an Ethernet cable or by a Wifi adapter, which is further connecting to a Wifi network.
 +
 +<imgcaption sparrowv3_topology | Monitoring topology>{{ proiecte:devicehub_architecture.png?800 | }}</imgcaption>
  
 <code C> <code C>
Line 377: Line 377:
  
 ===== Real time monitoring with Devicehub ===== ===== Real time monitoring with Devicehub =====
 +
 +Below you can see the Devicehub API we've used to monitor the parameters read by our Wireless Sensor Nodes. For simplicity, the code below is an example for only one monitoring node. If you'll use multiple nodes you'll need to add sensors / devices on Devicehub for each of them, then add code in the script for each of them. Of course, you'll also need to add your own PROJECT_ID, DEVICE_UUID and API_KEY as shown in the script below.
 +
 +One thing which should be mentioned is that we've empirically saw that the voltage ADC reported value is directly proportional in terms of volts with 1/71, hence we are dividing the ADC value to 71.
  
 <code python> <code python>
Line 399: Line 403:
 device = Device(project, DEVICE_UUID, API_KEY) device = Device(project, DEVICE_UUID, API_KEY)
  
-#1 
 temp_s = Sensor(Sensor.ANALOG, 'temp') temp_s = Sensor(Sensor.ANALOG, 'temp')
 light_s = Sensor(Sensor.ANALOG, 'light') light_s = Sensor(Sensor.ANALOG, 'light')
 rh_s = Sensor(Sensor.ANALOG, 'rh') rh_s = Sensor(Sensor.ANALOG, 'rh')
 battery_s = Sensor(Sensor.ANALOG, 'voltage') battery_s = Sensor(Sensor.ANALOG, 'voltage')
-sleep_s = Sensor(Sensor.ANALOG, 'sleep_time') 
  
 device.addSensor(temp_s) device.addSensor(temp_s)
Line 410: Line 412:
 device.addSensor(rh_s) device.addSensor(rh_s)
 device.addSensor(battery_s) device.addSensor(battery_s)
-device.addSensor(sleep_s) 
- 
-#send only at minimum 1 minute intervals 
-time1 = 0 
-time2 = 0 
  
 while 1: while 1:
  line = ser.readline()  line = ser.readline()
- if 0 == time1: 
- time1 = time.time() 
- time2 = time1 
- else: 
- time2 = time.time() 
   
  id_v = int(line.split(':')[0])  id_v = int(line.split(':')[0])
Line 429: Line 421:
  rh_v = int(line.split(':')[5])  rh_v = int(line.split(':')[5])
  battery_v = int(line.split(':')[6])  battery_v = int(line.split(':')[6])
- sleep_v = int(line.split(':')[7]) 
   
- print "id:",id_v," temp:",temp_v," light:",light_v," rh:",rh_v," battery:",float(battery_v/71.0),"sleep_v:",sleep_v,"delta:",time2-time1+ print "id:",id_v," temp:",temp_v," light:",light_v," rh:",rh_v," battery:",float(battery_v/71.0)
   
- if ((time2 - time1) >= 60) or (0 == time2): + temp_s.addValue(temp_v) 
- temp_s.addValue(temp_v) + light_s.addValue(light_v) 
- light_s.addValue(light_v) + rh_s.addValue(rh_v) 
- rh_s.addValue(rh_v) + battery_s.addValue(float(battery_v/71.0)) 
- battery_s.addValue(float(battery_v/71.0)) + 
- sleep_s.addValue(sleep_v) + device.send()
- device.send() +
- time1 = time2+
 </code> </code>
 +
 +You can see below some snapshots from Devicehub.net for one of our nodes.
 +
 +<imgcaption sensors | Sensor on Devicehub for each node>{{ proiecte:sensors.png?800 | }}</imgcaption>
 +<imgcaption sensors1 | Light sensor>{{ proiecte:id7_light.png?800 | }}</imgcaption>
 +<imgcaption sensors2 | Relative humidity sensor>{{ proiecte:id7_relhumid.png?800 | }}</imgcaption>
 +<imgcaption sensors3 | Temperature Sensor>{{ proiecte:id7_temp.png?800 | }}</imgcaption>
proiecte/sparrowv3-devicehub.1444080979.txt.gz · Last modified: 2015/10/06 00:36 by alex.marin