Sunday, March 20, 2016

Working with Xbee's - Week 10 open project

I've been putting off my xbee project for awhile.  When I was working with it early on, I failed to document many of my resources, my failures and successes.  Recently I attended a session at the SXSWedu conference on Open Portfolios.  Essentially by not documenting my process, I failed to complete a portfolio of my learning. So, for Week 10 of Create with Code, I decided to go back and spend some time re-curating my resources and finally trying to get my damn Xbees working with a real sensor.
Here's a list of great resources for Xbees and Arduinos:

The first is from TunnelsUp.  There are 5 videos in this series that go over some excellent material on how to set up the Xbees with XCTU software, learn about Coordinator and Routers and setting up a network.  I also learned how to jump my chip on the arduino and make a serial connection hack - which saves about $25 on a device that does the same thing.
 
The next best resource from the same author is the Xbee Cheat Sheet he made to better understand all of the pin locations, settings and basics.   I use this sheet often.

Both AdaFruit and Arduino Forums have a fair amount of information on the Xbees and even better, information on sensors, especially Adafruit.   The Arduino forum has a couple of members that are pretty curt with responses.  One member responds to most queries in the forum, but I've noticed a pattern around how poorly he treats people with questions.

YouTube has been really valuable.  There are a lot of people building interesting things with the Arduino.  I found someone who is doing something similar to what I want to do, except he is using a temperature and humidity sensor to measure his chicken coop.

Well, on to my project.  Step one was to get the two Xbees to communicate.  Check!  Using the XCTU software on two computers, a student in CST, an instructor of the same course and me set up a xbee network and communicated on the same channel through a terminal window.  I recreated this same "Chat" this past weekend just to make sure both my Xbees were working correctly.

Step two:  hook up a temp sensor (I just bought a fresh TMP36) from Amazon as well as a DHT11 sensor.  Both worked well, running the Sketch #7 in the SIK Sparkfun Guidebook for the TMP36 and the AdaFruit Sketch for the DHT11.

Step three:  Draft up my sketch (see my video below) and plan my network.  So far, it made sense on paper.  I built the sensor, configured the xbees and used some sample code from TunnelsUp (found in Video 4 of his series).

Step four:  Frustration.  After an hour, I finally got my xbees to communicate.  I think either the router went to sleep, or the wrong port was called for communication.

 

This video shows my progress so far.  I've been able to set up a connection and reliably communicate from the router back to the coordinator.  However, I cannot seem to get the voltage right, as it does not appear that the Code is sending the right information packet for the sensor to grab.  I spent about six hours debugging, re-coding and troubleshooting.  I am totally at a loss on what might be happening.  I am going to meet with the CST department for some new direction.  Ultimately I want to hook a digital sensor (ds18b) to send temp information.  If I can't get the analog to work, I don't know how I am going to attack my compost temperature project.

Here is the code I am using to call the sensor.

float temp;
void setup() {
 
  Serial.begin(9600);
};


void loop() {
  if (Serial.available() >= 21) {
    if (Serial.read() == 0x7E) {
      for (int i = 1; i < 19; i++) {
        byte discardByte = Serial.read();
      }
      int analogMSB = Serial.read();
      int analogLSB = Serial.read();
      int analogReading = analogLSB + (analogMSB * 256);
      temp = analogReading / 1023 * 1.23;
      temp = temp - .5;
      temp = temp / .01;
      temp = temp * 9/5 + 32;
      Serial.print(temp);
      Serial.println("degrees F");
    }
  }
}
 

No comments:

Post a Comment