User Tools

Site Tools


introduction_to_the_internet_of_things

THINGS TO DO BEFORE THE CLASS

Software Setup You should do the following things before the class:

If you are using a Macintosh, install these drivers for the serial board - https://github.com/adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver. I find the CH34x serial chip support on OS X to be spotty at best. Follow the instructions carefully. YOU MUST DELETE ANY OLD VERSIONS OF THE DRIVERS, or kernel panics WILL happen! Linux and Windows machines should just work, but if not look for the current CH34x drivers.

Install Arduino IDE if you don't already have it, and upgrade to something recent if you're below version 1.7 - http://arduino.cc

Set up a Cayenne account - https://cayenne.mydevices.com

  • Click on “Add new…”
  • In the page that comes up, click “Bring Your Own Thing” The page that brings up will have your MQTT username/password/client ID information

Install the following libraries:

For each of these four libraries, click on the “Clone or download” button, and download the ZIP file (more complicated things can be done if you're Git savvy, but plain old zip download is fine here…) From there, you should be able to install the libraries using Sketch→Include Library→ Add .ZIP Library (you may need to strip the -master from the .zip files filename)

Modify BME280 library:

  • on OS X, navigate using the finder or otherwise cd ~/Documents/Arduino/libraries/Adafruit_BME280_Library-master/
    • On Windows & Linux the files will be somewhere similar - you can find your base directory via Preferences, and from there get to the libraries folder
  • edit Adafruit_BME280.h using your favorite editor, and change #define BME280_ADDRESS from 0x77 to 0x76- it should be around line 34 or so.
  • I originally had some stuff about modifying the library further, but it didn't work. Just do this, and remember to change it back if you ever get an official Adafruit BME280 breakout board.

If Using Your Phone to Tether

I have not tested phone tethering- the prototype worked directly with our in-space WiFi. However, if you wish to try it, there are some instructions to be found here:

THINGS WE WILL DO AT THE CLASS

Your kit should consist of a number of boards:

  • ESP8266 Wifi-enabled microcontroller
  • BME280 sensor array
  • AMS1117 voltage regulator
  • CH34x-based programmer for the ESP8266
Hardware Construction
  • First things first- TEST THE VOLTAGE REGULATOR BOARD. Unfortunately, these boards are capable of failing short (i.e. the input voltage can end up at the output, which will fry your ESP8266!!). Hook up your power source to the Vin of the regulator board. Using a voltmeter, check the voltage at Vout. It should be about 3.3V, give or take .1 V. If it is more than this, get another board and throw this one away!
  • On the programming board, wire an SPST or SPDT switch between GPIO and GND
  • If you plan on re-using the boards for something else in the future, solder in header pins on the other boards. If you're building this as a fixed-in-place design, you'll want to just solder wires to the boards. Theoretically, the person that designed this de-solders the pins from the ESP8266 board, but that seems foolhardy to me (makes it MUCH more difficult to reprogram…)
  • wiring:
    • ESP8266→BME280: GND→GND, IO2→SCL, IO0→SDA,3V3→VCC
    • AMS1117→ESP8266: GND→GND, VOUT→3V3
    • Note that the 3.3V & GND connections are going to multiple places.
Software Programming

This is the stock program for the class, with some minor edits to account for our BME280 header hack above.

#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <CayenneMQTTESP8266.h>
#include <SimpleTimer.h>

// Your network name and password.
char ssid[] = "your_mobile_phone_tether_ssid";  //  your network SSID (name)  
char pass[] = "your_mobile_phone_password";       // your network password  
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "xxxxxxxxxxxxxxxxxxxxxxx5c2";  
char mqtt_password[] = "xxxxxxxxxxxxxxxxxxxxxxxxx190";  
char client_id[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

// Virtual Pins of the BME280 widget.
#define TEMPERATURE_PIN V0
#define BAROMETER_PIN V1
#define HUMIDITY_PIN V2
#define  ALTITUDE_PIN V3

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C  
unsigned long delayTime;

void setup()  
{
  Serial.begin(9600);
  Cayenne.begin(username, mqtt_password, client_id, ssid, pass);
  Wire.begin(0, 2); // SDA, SDL
  bme.begin();

}

void loop()  
{
  Cayenne.loop();
}

// These functions are called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(V0)  
{
  // Send the Temperature value to Cayenne
  Cayenne.virtualWrite(V0, bme.readTemperature());
}

CAYENNE_OUT(V1)  
{
  // Send the Pressure value to Cayenne
  Cayenne.virtualWrite(V1, bme.readPressure());
}

CAYENNE_OUT(V2)  
{
  // Send the Humidity value to Cayenne
  Cayenne.virtualWrite(V2, bme.readHumidity());
}

CAYENNE_OUT(V3)  
{
  // Send the Altitude value to Cayenne
  Cayenne.virtualWrite(V3, bme.readAltitude(SEALEVELPRESSURE_HPA));
}

Power considerations The kit does not come with a power source. The regulator board requires at least 4.5V (and at most 15V!) to adequately supply 3.3V to the ESP8266 and BME280 boards. A 9V battery or 6V AA case should work. You should be able to power via USB with the serial board as well- just run wires from 3.3v & ground to the appropriate ESP8266 pins and leave out the AMS1117.

introduction_to_the_internet_of_things.txt · Last modified: 2018/08/22 11:09 by sdh7