Saturday, December 5, 2015

HOW TO: View Arduino Serial Data from Command Line

In the past I have always viewed the information I printed to the serial port within the Arduino IDE by opening the Serial Monitor.  However, you can view the same information from the command line.  To do so simply follow these steps.

Put this in an Arduino sketch:

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

void loop() {
Serial.println("ImagineN4tion, right MEOW!");
delay(500);
}



Upload it to whatever development board you are working with.

Then, on Mac, open Terminal and execute the following command:

ls /dev/tty.*



This will list all the serial connections.  Identify which serial port you would like to listen to.  Then execute the following command to listen to that port:

screen /dev/tty.[yourSerialPortName] [yourBaudRate]

You will enter your specific information to replace what is between the [ ] in this command.  Thus, for me it becomes:

screen /dev/tty.SLAB_USBtoUART 9600




A screen window will be opened within your terminal and you will be able to see whatever your development board is printing to the serial port, yahoo!  The sketch I provided above simply prints "ImagineN4tion, right MEOW!" repeatedly.







HOW TO: Up and running with Adafruit HUZZAH Feather ESP8266

INTRO:

Hello weary cyber-ether traveler!  The following is a quick HOW TO that describes how to connect a device to the internet that you can use to control things in the physical world.  We will be using a wifi enabled device called the "Adafruit HUZZAH Feather ESP8266" to connect to the internets.  Don't you worry if none of that makes sense to you or you are unfamiliar with some of the lingo and materials.  We play nicely with people whom are still learning and in pursuit of knowledge :).  


Hardware used:


  1. MAC Comp-ooter
  2. Adafruit HUZZAH Feather esp8266 (we will refer to as Huzzah from here on out) - https://www.adafruit.com/product/2821
  3. USB A/micro cable - https://www.adafruit.com/products/898


Software used:

Important:  Make sure to use an Arduino IDE version other than 1.6.6 as that version seems to not function well with the Huzzah ESP8266 boards.


  1. Arduino IDE version 1.6.5 - https://www.arduino.cc/en/Main/OldSoftwareReleases#00xx
  2. Silicon Labs VCP Driver Install Disk - https://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx



Initial Setup:

Download and install the software components listed above.

Then, open the Arduino IDE and click Arduino->Preferences and enter the below URL into the "Additional Boards Manager URLs" field in the pop-up box (See images 1-3).  

URL to copy paste into the Additional Boards Manager URLs field:
http://arduino.esp8266.com/stable/package_esp8266com_index.json


Image 1: Open Preferences

Image 2: Preferences Pop-up

Image 3: Adding the URL into the "Additional Boards Manager URLs" field.


Next click Tools->Boards->Boards Manager... and find "esp8266" in the boards manager.  Then click install.  (See images 4-5)

Image 4: Navigate to the Boards Manager...

Image 5: Find "esp8266" and install.



Now close down your Arduino IDE and restart.  Once you have done this, click Tools->Board->Adafruit Huzzah esp8266 (See image 6).



Image 6:  Choose the Adafruit HUZZAH ESP8266




Next, click Tools->CPU Frequency and choose 80mhz (See image 4).

Image 4: Selecting the CPU Frequency



Then, click Tools->Upload Speed and choose 115200 (See image 5).

Image 5: Selecting the Upload Speed



Connect the HUZZAH Feather to your computer with the USB A/micro (See image 6).

Image 6:  Connect your Huzzah to your computer



Then, click Tools->Port and choose the port your Feather is connected to.  It will likely say something like "USBtoUART" at the end (See image 10).  If not, there's always trial and error with a limited amount of ports.  Note, we had to deselect and reselect the port a couple of times when trying to successfully upload the sketch to our Huzzah.

Image 10:  Choose the port your Huzzah is connected to.


The Fun Stuff!

Now that we have properly set everything up let's try and get some code on our Huzzah.  Within the Arduino IDE, copy paste the following sketch, courtesy of the nice folks over at Adafruit (See image 11).


void setup() {
  pinMode(0, OUTPUT);
}

void loop() {
  digitalWrite(0, HIGH);
  delay(500);
  digitalWrite(0, LOW);
  delay(500);
}




Image 11: Copy code into the Arduino IDE


Then, in the upper left hand corner of the Arduino IDE, click "Verify" (See image 12) wait for the process to complete and then click "Upload" (See iamge 13) and the code will Upload to your Huzzah.  If everything goes off without a hitch, a red LED on your Huzzah will blink on and off.  Initially we received errors but after deselecting and then reselecting the Port (See image 8), it worked.  Note that some users have reported needing to connect pin 0 to ground to successfully upload the code.  Give this a shot if you are having issues.

Image 12: The Verify button in the Arduino IDE


Image 13: The Upload button in the Arduino IDE



Movie 1: Hello world, blinky time!

Next Steps

Go mobile with a lipo battery pack and make your Huzzah do something cool.  Use your ImagineN4tion...











Thursday, November 12, 2015

PHP - Render partial view within another controller's view

Goal:
Render a view called view_B within another view called view_A.  Note that view_B belongs to a different controller than view_A and thus is in a different directory.

Solution:
Put this within view_A's code, where "site" is the directory of view_B within the "views" directory and "dashmenu" is the name of view_B.

<?php echo $this->render('//site/dashmenu'); ?>

aka, generically:

<?php echo $this->render('//view_B_Directory/view_B'); ?>

Note that the "//" double slash here denotes the path is within the views directory.


There is also a more verbose way to do this:
<!-- a more verbose way -->
<?php echo Yii::$app->view->render('//site/dashmenu'); ?> 

PHP - Intro

Not a huge fan of PHP but unfortunately I was turned on to a framework called Yii2 to use during my first foray into web development.  My first iteration of a site that is an accompaniment to a piece of internet connected hardware has been built with PHP on the Yii2 framework.  The journey has involved a considerable amount of learning and I have decided to park some of those learnings here on Somewhere in the Boundary Layer.  Thus, you will start seeing tidbits of knowledge that I want to log for future use in short posts.

As an aside, I have been hardware hacking a lot with node.js as well.  Thus, you will find some node and socket.io strewn about the blog as well.  If you're going to follow suite with either choose node.js and not php as node is better suited for event driven programming for connected devices.

Monday, November 2, 2015

Internet Connected LCD

Built an internet connected LCD using an Adafruit Huzzah ESP8266 board, the Arduino IDE, node.js and socket.io.  Here's a short video of it in action and a link to a page where you can write your own message to the LCD screen.  Send your twitter handle to the LCD and I'll tweet a pic of it back at ya!



Here's a page to play with the LCD:

http://fast-bayou-5924.herokuapp.com/


Here's a video of it in action:



Saturday, October 31, 2015

HOW TO: Connect ESP8266 to LCD via i2c

Bonjour-nO!  This post will show you how to connect an Adafruit Huzzah ESP8266 board to a standard HD44780 LCD via i2c.  I just did this myself and it took way too many google searches to battle through dumb issues so I hope this saves you some time.



MATERIALS:

Adafruit Huzzah ESP8266 board (other esp8266 boards might work as well but this was done using the huzzah board) - https://www.adafruit.com/products/2471
USB to serial cable - https://www.adafruit.com/product/954
Bread board
Male and Female wires for breadboarding
LCD (we use a 16x2) - https://www.adafruit.com/products/181
i2c backpack - http://www.adafruit.com/products/292
Arduino IDE



ASSUMPTIONS:

 I will assume you know how to setup your Arduino IDE to program the esp8266 huzzah board.  If you do not know how to do this, checkout my instructions on those topics here: <to come>.  (See also Adafruit's tutorial, https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide).  I'll also let you follow Adafruit's tutorial on how to get the i2c backpack soldered onto your lcd, https://learn.adafruit.com/i2c-spi-lcd-backpack/overview.



DEALING WITH LIBRARIES:

The most brutal part of making this work was figuring out what libraries I had installed in the Arduino IDE, which were duplicate libraries, and where all of the libraries were found.  The two libraries you need for this project are...

  • Wire
  • LiquidCrystal (the updated version that includes i2c support)

It is important to note that there are multiple locations with libraries that the Arduino IDE references.  Here is a synopsis of the locations of my library files (yours may be slightly different) and descriptions of what each location contains.

  1. The libraries you manually load, found within the "libraries" folder in the same folder your sketches are saved to - C:\Users\YOUR_NAME\Documents\Arduino\libraries
  2. The libraries that the Arduino IDE comes with, found within the location that you installed the Arduino IDE - C:\Program Files (x86)\Arduino\libraries
  3. The libraries that were installed when you setup the Arduino IDE to be able to program your ESP8266 - C:\Users\YOUR_NAME\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\libraries

Your goal is to ensure that there is only ONE copy of the Wire.h and LiquidCrystal.h libraries for the ESP8266 which is up-to-date and installed.

For the Wire library, I ended up going into locations 1 and 2 listed above and moving out any folder and it's contents named "Wire" since the Wire library was installed into location 3 with the other esp8266 libraries upon setting up my Arduino IDE for esp8266 boards.  If the Wire library was for some reason not installed into location 3, you can find all the esp8266 libraries here:
https://github.com/esp8266/Arduino/tree/master/libraries
Any libraries I moved out I just tossed into a backup folder somewhere to store them in case I needed to revert back.

For the LiquidCrystal library, I moved all LiquidCrystal folders and files out of locations 1, 2 and 3 into my backup folder.  I then downloaded the i2c supported version of the library from Adafruit here:
https://github.com/adafruit/LiquidCrystal
and installed it via the the Arduino IDE's zip file library loader (Click Sketch-->Include Library-->Add .Zip Library...).

Once you have done these two things you should be able to go to "Sketch-->Include Library" and see both the "Wire" and "LiquidCrystal-master" libraries under "Contributed libraries".



WIRE IT:

First things second, let's get this sucker wired up.  We are going to power the whole shoot-n-shebang off the USB to serial power wire.  Here's a pinout that will help you figure out what to connect to what:

Device Pin Connect to Device Connect to Pin
USB to Serial Cable Rx (3.3V, white) ESP8266 Huzzah Tx
USB to Serial Cable Tx (3.3V, green) ESP8266 Huzzah Rx
USB to Serial Cable Power (5V @ 500mA) Breadboard Power Rail
USB to Serial Cable GND ESP8266 Huzzah GND
i2c Back Pack LAT none none
i2c Back Pack DAT ESP8266 Huzzah 2
i2c Back Pack CLK ESP8266 Huzzah 14
i2c Back Pack 5V Breadboard Power Rail
i2c Back Pack GND Breadboard GND Rail
ESP8266 Huzzah GND Breadboard GND Rail




CODE IT:

Next, you will go through the usual process to save code to the Huzzah board by holding down the GPIO0 button, clicking the "Reset" button and then letting go of the GPIO0 button.  This action sets your board into bootload mode and you can then click to upload the sketch from the Arduino IDE.  You will use the following code to upload to your board.
The code can also be found here:



/*
 Demonstration sketch for Adafruit i2c/SPI LCD backpack
 using MCP23008 I2C expander
 ( http://www.ladyada.net/products/i2cspilcdbackpack/index.html )

 This sketch prints "Hello World!" to the LCD
 and shows the time since the board was reset.

  The circuit see: http://www.imaginen4tion.blogspot.com/2015/10/how-to-connect-esp8266-to-lcd-via-i2c.html


*/

// Originally written by Adafruit.
// Modified for esp8266 by Bob Rowe on 10.31.15, giddyup!

// include the library code:
#include "Wire.h"
#include "LiquidCrystal.h"
// Note, problems with your libraries is a common issue due to multiple
// libraries with the same name getting imported into your Arduino IDE
// when setting up to develop on esp8266.
// See for more info:


// Connect to LCD via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);
// "Default address" simply refers to how your Adafruit i2c backpack is setup.
// See here for more info:  https://learn.adafruit.com/i2c-spi-lcd-backpack/connect-to-i2c

void setup() {
  // Initiate the i2c connection on esp pins 2 (DAT/SDA) and 14 (CLK/SCL)
  Wire.begin(2,14);

  // set up the LCD's number of rows and columns:
  // Here we are using a standard LCD with 16 columns and 2 rows
  // example of LCD:  https://www.adafruit.com/products/181
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);

  // print the number of seconds since reset:
  lcd.print(millis()/1000);
  lcd.setBacklight(HIGH);
  delay(500);
  lcd.setBacklight(LOW);
  delay(500);
}




TROUBLESHOOT:

Problems with libraries - search your computer for the library.h file you are having issue with, eg: search "Wire.h".  Then ensure that you only have one version of that library within the Arduino IDE's reach.
Uploaded code to Arduino and nothing is happening - Test that the pins you are using for DAT and CLK (2 & 14 in the code above) are working correctly.  Find an LED and turn it on and off or read the voltage coming out of the pin.  Also, ensure your LCD is good by seeing if the backlight will turn on by feeding 5V to pin 15 and GND pin 16.



Good luck, I hope this helps!





<adventures in hacking etsy seo>
shop
Chicago Laser Cut Coasters
blog filler
</adventures in hacking etsy seo>