Saturday, September 3, 2016

Microsoft: Refrigerators, not now - IoT Basics, yes please

Microsoft and Liebherr announced yesterday they are collaborating on a new "SmartDeviceBox" that allows the kitchen appliance to remind people what they need at the market, Microsoft principal data scientist TJ Hazen said in a blog post.

Fir now, let's not make jokes about your refrigerators updating at bad times or having blue screen of death episodes.

Rather, let's connect this announcement with an article that was published by former Apple executive Jean-Louis Gassée (link here). Most Internet of Things watchers are very skeptical right now. With some companies discontinuing the services behind their products and support often horrible, the consumer space has been very mixed. And some of the ideas are just not well thought out.


Gassée states 'The IoT randomly works. Devices stop and restart, they require visits to unsupportive customer support pages and helpless Your Call Is Important To U.S. help lines (and now we have chatbots). If you think I exaggerate, google “Nest trouble” or “smart bulbs trouble”.... Companies buy the cheapest possible processor, grab some software from the open source shelves, throw on a skimpy UI, hastily assemble and test, ship it.' Then he states "After a device has made it to the market, the real fun begins. Software updates are a problem when your connected lock or your connected car is in the middle of an update and you need to get in the house or drive to the emergency room."

If you look at my favorite vantage point, security, on that topic Gassée writes "Then there’s the truly ugly side of Consumer IoT: security, or the lack of it. The lackadaisical, to be polite, approach to software leaves many connections open to hackers who can see passwords exchanged in clear text on home WiFi while they sit in a car parked outside the house. Or we see that 100M Volkswagen cars are open to wireless hacking."

Then let's look at standards.

On Twitter, Alasdair Allan (@aallan) states: The #iot has 3 problems; security, refresh cycle, and standards. Of these standards least important, but only one the Valley cares about.

Companies don't often want cross-company standards. The classic "if we build our own ecosystem, we can keep people buying only our products" (examples: Nest, Apple).

Ok, so much for the doom & gloom (for now).

Getting back to Microsoft. They are jumping on refrigerators and cars and what not. But this is the perfect opportunity for Microsoft or whomever to be a pivotal group in spurring the Internet of Things. How? Make it easier for people. Connecting IoT devices to the home and talking to each other is currently hard. Microsoft knows this space, they can make it easier for us. Take Windows 10 IoT and double the staff and tie them into your research group.  Make It Simple is the goal.

I never want to have to reboot my GE smart bulb, certainly not having to do this manually, that is not asking too much. If Microsoft got IoT basics right, it wouldn't matter if company X did a great Kickstarter, then 2 years later went out of business - if we had common basis, things would still work in a standard way which communicates in a way that is easy to use (thanks to Microsoft or whomever heeds this).

A starting point. Integrate the DynDNS type service in. Microsoft did it for Windows Home Server, they know how.  Bake it in. Keep building in the simple, positive steps.

We didn't go to the moon on the first launch. Microsoft and others, ensure you build a standards compliant base which includes security and intercompatibility, for IoT to grow on.

Wednesday, August 24, 2016

An Adafruit Circuit Playground Rolling in a Pringles Can

Good response today as I posted on social media the picture below - the Adafruit Circuit Playground low cost experimenter board and a 3xAAA battery pack fit well in a Pringles potato chip (crisp) can:


So I have been playing with the accelerometer sensor in the Circuit Playground. You can do some sophisticated things with an accelerometer.  Let's see what I did with the can.

Parts:
Adafruit Circuit Playground experimenters board - $19.95
3xAAA Battery Pack - $1.95
3 AAA batteries
Pringles Can - from the bin
Putty - from the craft supplies basket

Use some Blu-Tack, silly putty, clay, etc. to attach Circuit Playground to the battery pack. Just be sure the adhesive is not permanent and non-conductive. Plug the battery pack into the Circuit Playground and turn it on. Slide it into the can, it'll fit fine and not slide around (yay!).



First, I'll light up one Circuit Playground LED NeoPixel green. Program Circuit Playground with the first sketch below (which turns on NeoPixel #2).  Then I put the Circuit Playground into the can so it is fixed to the bottom. Then I roll the can. The LED will do loop-de-loops in circles similar to the following diagram:

And in the dark it looks like this:

Now, say I want the LED to always be at the top of the can. I can try to time the lighting of the LED to the rate at which I spin the can but I'm not a good can roller and it would get all messy.

So I use the accelerometer on Circuit Playground to tell which way is "up" as the can rolls at any speed.  An accelerometer measures both the pull of gravity on the sensor and changes in movement. If you roll Circuit Playground like we did above, there will be changes in the X and Y directions (the Z axis doesn't change rolling the can as I have mounted it).  See the board for which ways are

Is keeping the LED lit at the top of the ring as the can rolls even possible?  Yes. It takes some math though. You can read the acceleration values as the can rolls in rolling distance and as the can presses on the ground due to gravity. Kind of like the figure below from the Wikipedia article Circular Motion under the non-uniform heading
Program the Circuit Playground with the second sketch below. The code boils down to finding the angle between the x and y values of the accelerometer reading, calculating an angle. That angle is used to determine which of the 10 NeoPixels on Circuit Playground needs to be lit to remain at the top of the ring. That method allows for the rate of rolling the can (shown as v in the diagram) to vary and the rate of rolling does not matter (except a tiny bit for code speed). 

The LED at the top of the circle is lit at all times. It looks like this in the Pringles can:


So with little more than an empty can, Circuit Playground and a battery pack, we've used a bit of sensing and programming to make something do what intuitively it shouldn't do. This behavior is actually VERY useful and can be used to make bigger and better things.

And that's the beauty of Circuit Playground.  You can do so much with the capabilities onboard and you don't need to buy a lot of stuff to make it do great things, just look in the cupboard perhaps.

Code


Code for one LED:

// CPoneLED
//
// Set for Circuit Playground to display one LED Continually
//
// Mike Barela  August 23, 2016  MIT License

#include <Adafruit_CircuitPlayground.h>

#define brightness 16

void setup()
{
  CircuitPlayground.begin();
  CircuitPlayground.setBrightness(brightness);
}

void loop()
{
  if(CircuitPlayground.slideSwitch()) {
    CircuitPlayground.setPixelColor(2,0,brightness,0);
  }
  else {
    CircuitPlayground.setPixelColor(2,0,0,0);
  }
  CircuitPlayground.strip.show();
}

and code for the accelerometer aided LED:

// CPaccelerometerLED 
//
// Set the LED at the "top" of the Circuit Playground NeoPixel ring
//   no matter the x or y orientation (like when rolling)
//
// Mike Barela  August 23, 2016  MIT License

#include <Adafruit_CircuitPlayground.h>

#define NUMBER_OF_LEDS_ON_RING 10
const int brightness = 16;
int ledPosition, currentQueueSize;

void setup() {
  CircuitPlayground.begin();
  CircuitPlayground.setBrightness(brightness);
  CircuitPlayground.clearPixels();
}

int led, previousLed=0;
float x, y, nx, ny, angle; 

void loop(){

  x = CircuitPlayground.motionX();  // Read the accelerometer X & Y
  y = CircuitPlayground.motionY();
  nx = x / 10.0;                    // Scale to -1 to +1 in
  ny = y / 10.0;                    //    both directions
  angle = atan((ny/nx)) * 180 / 3.14; // get the angle from "down"

  if(angle > 0.0){   // As Arctangent won't give the angle over the
    if(nx < 0.0)     // entire 360 degrees, adjust depending
      angle += 180;  // on direction the acceleration was going
  } 
  else {
    if(ny > 0.0)
      angle += 180;
    else
      angle += 360;
  }

  if(angle == 360.0)
    angle = 0;

  // We have 10 LEDs in a circle - need to light the right one
  led = circularize(angle / (360 / NUMBER_OF_LEDS_ON_RING));

  // make led movement smooth
  if(previousLed == led){  // no movement, just reloop
    // nothing to do 
  }
  else if (counterClockwiseDistanceBetweenLeds(previousLed, led) <= 8) {
    led = circularize(previousLed + 1); // change detected, 
    makeLightShow(previousLed, led);    // change LED
    previousLed = led;
  }
  else {
    led = circularize(previousLed - 1);
    makeLightShow(previousLed, led);
    previousLed = led;
  }

  delay(25);
}

void makeLightShow(int previousLed, int led) { // light NeoPixel
  CircuitPlayground.strip.setPixelColor(previousLed,0,0,0);
  CircuitPlayground.strip.setPixelColor(led, 0, brightness, 0);
  CircuitPlayground.strip.show();
}

int circularize(int pos){ // if a position gets to be < 0 or > 9
  if(pos >= NUMBER_OF_LEDS_ON_RING)
    return(pos - NUMBER_OF_LEDS_ON_RING);
  else if(pos < 0)
    return(pos + NUMBER_OF_LEDS_ON_RING);
  else
    return(pos);
}

int counterClockwiseDistanceBetweenLeds(int prevPos, int nextPos){
  int distance;
  distance = nextPos - prevPos;
  if(distance < 0)
    distance += NUMBER_OF_LEDS_ON_RING;
    
  return(distance); 
}

An exercise for the student / magician is to make one sketch, it acts one way with the slide switch at the + position, another when switched to -.

Code heavily modified from https://petervojtek.github.io/diy/2015/01/24/neopixel-gravitation.html, the page gives some good info on the subject also.

Thursday, August 18, 2016

New Project: Adafruit Circuit Playground Sound & Music

My latest work was posted yesterday on the Adafruit Learning System. Their new Circuit Playground experimenting board has alot of uses. I explored using the onboard speaker to make sound and music. It progresses using the onboard light, temperature, and motion sensors. Finally it is programmed to play a Simon lights and sound game using the capacitive touch pads. It's a very flexible board.
Circuit Playground from Adafruit
See the full tutorial at https://learn.adafruit.com/circuit-playground-music

There will be more demos for this board - do you have ideas for projects?


Saturday, July 23, 2016

NeoPixel Rings in Poke Ball Colors

Just a quick post.  I'm playing with NeoPixels lately.  One set for my entry in the GE-Make-Hackster.io contest Lights for Life Challenge for one concept. The other is Adafruit's new Circuit Playground educational board.


Unless you've been stuck upgrading all your computers to Windows 10 before the deadline of July 29th, you may have heard that the 2000's sensation Pokemon has been reborn in a new augmented reality game Pokemon Go.

Poke Balls are the red and white spheres that a person uses to catch Pokemon.

Adafruit's NeoPixel light rings can be set to half red and half white to simulate a Poke Ball.

The code below has been set for the 10 pixels on Circuit Playground.  The code can be used on any Adafruit NeoPixel ring with quick changes to the constants at the start.

Have fun!

// CPpokeball   Paints your Adafruit NeoPixel ring in Poke Ball colors
//
// Set for Circuit Playground but works for all Adafruit NeoPixel Rings with
//   correct pixel pin number and pixel count 
//
// Mike Barela  July 23, 2016  MIT License

#include <Adafruit_NeoPixel.h>

const int pixelPin = 17;         // NeoPixel pin number for Circuit Playground
const int pixelCount = 10;       // Number of Neopixels (10 for Circuit Playground)
const int pixelBrightness = 30;  // 0 to 255

Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, pixelPin, NEO_GRB + NEO_KHZ800);

uint32_t red = strip.Color(255, 0, 0);
uint32_t white = strip.Color(255, 255, 255);
uint32_t black = strip.Color(0, 0, 0);

void setup()
{
  // this resets all the neopixels to an off state
  strip.begin();
  strip.show();
  strip.setBrightness(pixelBrightness);
}

void loop()
{
  setPixelsPokeBall();              // set Pokeball colors
  delay(5000);                      // delay 5 deconds
  for( int8_t j=1; j<=5; j++) {     // blink Pokeball colors 5 times
     setPixelsOff();
     delay(700);
     setPixelsPokeBall();
     delay(700);
  }
  delay(2000);                     // wait a bit and start again
}

void setPixelsOff(void) {
   for(int8_t i=0; i<=9; i++) {
      strip.setPixelColor(i, black);
   } 
   strip.show();
}

void setPixelsPokeBall(void) {
    for(int8_t i=0; i<(pixelCount/2); i++) {
        strip.setPixelColor(i, red);
    }
    for(int8_t i=(pixelCount/2); i<pixelCount; i++) {
        strip.setPixelColor(i, white);
    }
    strip.show();
}

Sunday, June 19, 2016

Arduinos, New Arduinos, and Pin Header

With a new crop of Arduino compatible boards in "non-traditional" form factors, you may need to consider what type of header pins you want to use on the boards.

Pin header is typically used for:
  • Easier connection to a breadboard or to connect wires (electrical)
  • Connecting other boards via stacking (mechanical)
Below is the classic Arduino stacking header shield (for prototyping) and that board stacked on an Arduino R3 (right). The shields for the classic Uno R3 are an 8 pin + 10 pin header on top (half-pin space between), and a six pin and 8 pin header opposite (one pin space between, some boards put a nonfunctional header pin between like on the new Arduino Uno WiFi). Boards made since the Arduino Zero have an additional ATN pin on the side closest to the power jack.
Arduino Stacking Shield with female header with long pins (via adafruit.com)
A shield will need long male pins beneath and the Arduino typically has female pins on top to make the connection.  Note the shield above has female pins on top so another shield may be stacked on top of that.  If a shield does not need to have another shield stacked on top, you can use plain male header.
Arduino compatible Feather with long female pins for Breadboard, display "shield" on top with male non-stacking pins (via adafruit.com)
The pictures above demonstrate several things: The Adafruit Feather arduino-compatible board on the left has female header with long male pins to be able to be pressed into a breadboard.  The display on top has regular male pins soldered on.  The picture on the right shows the two types of header.

Mail order companies (Adafruit, Sparkfun, Farnell, eBay, etc.) sell a lot of different types of header for your making use. Male, female short, female long, single row, double row, and header with 90 degree bends. Male header even comes in extra long for certain applications. Header can come in many widths, the most common when buying header alone is in 40 pin pieces/sticks, although vendors will often sell shorter lengths for specific purposes.

A few different types of header (yes there are many more types)
Most header is built with a tenth of an inch spacing between pins (0.1" or 2.54 millimeters metric). For some items like XBee radio and some ESP8266 breakouts, they use 2 mm spacing, and some boards may use other spacings. Be careful on guessing the spacing for certain components, boards, displays, etc. Always measure or count twice.

Now on to some of these new Arduino compatible boards coming out. The header pins in the Arduino R3 pictures are nice but they are usually made for 14 on the short side and 18 on the other side. These will not work on some other boards.  Here are the header pin counts for some modern boards:

Adafruit Feather has 12 pins on one side, 20 on the other

Arduino.cc MKR1000 has 14 pins on both sides

The Adafruit Huzzah ESP8266 Board has 10 pins on either side (they give you a few extra pins in the header strips)

The NodeMCU ESP8266 board has 15 pins on either side

Making Custom Header Widths


If you have header that is longer than the board you need it for, you can usually cut the header pieces to fit. This may also save money, buying 40 pin sticks and cutting to fit your project.

You should wear eye protection and use caution when preparing to cut header, pieces will fly off!!

Use a good pair of diagonal cutters.  Some header, like the male ones, have a groove between pins, making it easy to make a clean cut (often called "breakaway header").  Female header is trickier. Center the cut about in the middle of the next pin after counting out the number you need.  Make a straight cut.  Be careful as the gold pin will fly out

Cutting male header (left) and female header (right).  Via learn.adafruit.com
This will leave that side with a bit of a U shape. You can use good cutters to do further trimming. Then use a file to get a nice smooth edge.

Soldering Header


The secret: Use a breadboard or another board with header pins to hold the board to be soldered in place. Have a hot soldering iron and heat each pad+pin and solder.

learn_arduino_solder5.jpg
Using one board to hold pins for another (via learn.adafruit.com)

With a breadboard, put the pin header in, then the board, then solder.  You can also put a piece of male header in a breadboard to secure a female header to solder onto a board (a good use for the extra-long male header). Be sure the board you are soldering is level, once the solder cools, it is hard to level out.

What are your tips for using header in your projects?

Saturday, April 9, 2016

Use Adafruit Feather Wings as MKR1000 Shields

The MKR1000 microcontroller board from arduino.cc is a very new, very powerful board. With the board coming out of beta and now available, the pinout of the board is fixed (compared to the "pinout might change" communicated in the beta).

It will take some time for MKR1000 compatible daughterboards ("shields").

Fortunately, Adafruit makes add-on boards for their new Feather line. Feather comes with several different microcontrollers: AVR 32u4, SAMD21 M0, ESP8266 and some also come integrated with nice radios. Peripheral daughterboards (Adafruit calls "Wings") now available include LEDs, a real-time clock, motor control, relay, servo, and OLED display.

In the absence of MKR1000 shields, you can look to use Feather Wing boards.


Wings are not directly pluggable into headers placed on the MKR1000.  The pinouts are different and the M0 processors on the Feather M0 and the MKR1000 are different (SAMD21 vs. SAMW25 respectfully).

To overcome the differences, a sandwich board can be used. This would best be a custom board (think a nice purple PCB with ma1e headers on the bottom, female on the top). with the pins from the bottom switched around to make the top pins fit the Feather Wing pin expectations.

For a proof of concept, I took two Adafruit Proto Feather Wings. They were used to make the wiring changes.

Above, the MKR1000 is the bottom board furthest from the display.  It has female headers (with extra long pins for breadboard use also) soldered in (shown below).


The second board, a proto, has two sets of male pins, ones to make with the MKR1000 and male headers pointed up towards the second proto.

The second proto has male headers pointing down to the first and female headers for the Feather Wing daughterboard.

The cross connection may be done with 22 gauge wire.  A more old fashioned connection method is to use fine wire wrap wire and connect with a wire wrap tool. See Wikipedia if you're unfamiliar with wire wrapping.

The OLED Feather wing communicates via the I2C bus. To make it work, we need to cross connect the following pins:

  • Ground
  • Power / 3.3 volts
  • I2C data line (SDA)
  • I2C clock line (SCL)
  • The reset line for the display is connected to Pin 5 on the MKR1000
The code to put test text on the display:


/*
 *  MKR1000 and Adafruit Feather Wing Code
 *  Mike Barela http://21stdigitalhome.blogspot.com/
 */
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 5
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup() {
  
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  
  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  display.display();
  delay(2000);
  // Clear the buffer.
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("Connected to");
  display.setCursor(0,16);
  display.print("MKR1000!");
  display.display(); 
}
void loop() {
}
Have fun wiring additions to your MKR1000 board including using Adafruit Feather wings.

Thursday, March 31, 2016

Cross Compiling Post Mortem

My article series a few days ago on Windows cross compiling for Raspberry Pi hasn't caught fire.

Today has the announcement from the Microsoft Build conference that an upcoming Windows 10 update will include the Ubuntu user environment and ability to run Ubuntu executables.  Wow.

This means a much easier time working on development.  We'll have to wait for the Redstone upgrade, no date given, then use a Windows 10 machine.  Worth upgrading from Windows 7?