Showing posts with label HOW TO. Show all posts
Showing posts with label HOW TO. Show all posts

Saturday, December 5, 2015

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'); ?> 

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>



Sunday, June 9, 2013

HOW TO: Connect your Arduino to the Internet as a Web Server

The INTERNET OF THINGS...
< queue lightning and thunder >

It's what all the cool kids are doing these days.  Why should they have all the fun?  Let's setup an Arduino as a Web Server that anyone, anywhere can view.  Why would we do such a thing?  Possible projects include collecting data from a sensor and posting it to the Web or controlling an actuator remotely.  Think internet connected fart sensor that logs realtime how awesome your roommate's flatulence is, or perhaps, a robot that hides in the bushes and pokes pedestrians sauntering by.

Here is a quick video detailing the setup that I will take you through.  We have a servo and an LED that are controlled via a Web page.  The control page is accessible from both the private and public networks (aka: internet accessible for anyone).  The video shows me turning both the servo and LED on and off from my computer and iPhone (with the wireless network turned off so as to force it to access the Arduino from the public network).  I also have a live video feed coming from a wireless IP camera so that you can view what is happening remotely in the case you were to use this functionality for a remote control application that required monitoring of the system.

Awesome, so let's starting tinkering on Al Gore's interweb.  Here's how to do it and what you'll need:

Materials:
1)  Internet connection
2)  Internet router and associated information (LAN IP address, WAN IP Address... don't panic more on this soon)
3)  Arduino
4)  Arduino compatible Ethernet shield (I am using the shield by Seeed Studio)
5)  Ethernet cable
6)  Computer with Arduino programming ability


Lingo:
1)  LAN = Local Area Network
2)  WAN = Wide Area Network
3)  IP Address = Internet Prototocol Address
4)  ISP = Internet Service Provider Lets get going!



STEP 1:  COLLECT INFORMATION ABOUT YOUR HOME NETWORK  


First things first, you need to find the following information about your home network:

a)  The login name and password for your router.  My login credentials were listed on the back of my router on a sticker.  They were super complex credentials... Login = "admin", Password = "password".

b)  Your LAN IP address (aka: Private IP address) and/or your router manager login site.  I have a NetGear router and it listed the router manager login site on the back sticker as http://www.routerlogin.net.  If you do not have something similar on your router try entering these standard LAN IP addresses into your web browser 192.168.2.1,  192.168.0.1, 192.168.1.1 .  You will know it works if you land on a page that requests a login and password (which should be provided on the back of your router or in documentation from your internet service provider).  If you connected via a router login site, you can then find your LAN IP by browsing around and finding a page that details your LAN.  The IP address will generally be of the form xxx.xxx.x.x.

 c)  Your WAN IP address (aka: Public IP address).  This one is easy.  Just google "what's my ip address".  Google returns your WAN/Public IP address.  This information will also be listed once you login to your router.




STEP 2:  PLUG N' CHUG 


 a)  Plug the Ethernet shield into your Arduino.

b)  Plug your Arduino into your computer via the USB cable.

c)  Plug your Ethernet cable into the Ethernet shield and the other end into an open Ethernet plug on your router.




STEP 3:  SETUP PORT FORWARDING 


If we want anyone, anywhere to have access to the Arduino Web Server we need to setup something called port forwarding.  This is an option you can set within your Internet router manager.  To make a long story short, port forwarding will allow interactions between the WAN and the LAN, aka:  It exposes your Arduino to the Public network as opposed to keeping it isolated in the Private network.  Thus, anyone, anywhere with Internet access can interact with your Arduino.

a)  Find the IP address of your Arduino.  To do this login to your router manager (see Step 1 parts a & b).  Once logged into your router, find a page titled something similar to "Attached Devices".  Once here, you will be able to see the LAN IP address unique to your Arduino, commonly 192.168.1.177.

b)  Once you have the Arduino LAN IP, find a page within your router called "Port Forwarding".  From here you will have to find the option to "add custom service" or something similar.  To setup a new custom service, enter the LAN IP address of your Arduino, choose TCP/UDP for protocol, choose an open port, how about 8081 - use this number for both the starting port and ending port, and a name for the new service.  Once created, your new custom service (port forwarding for your Arduino) it will show up in the port forwarding list.




STEP 4: CODE AND TEST  


Now that all the network bogusness is taken care of we can focus on making widgets whirl.  This code creates a Web Server that can be accessed by entering "http://xx.xxx.xx.xx:8081/"  where, xx.xxx.xx.xx is your WAN IP address.  If you used a different port than 8081 just change the last digits following the ":" to the port you used.  The web page has 5 buttons that control an LED on pin 9 and a servo on pin 6.

a)  Save the code down to your Arduino.  Get code here:  http://bit.ly/1OfRnN3
Note, this is modified code relying heavily on code from the following source: Arduino Cookbook, Second Edition, by Michael Margolis with Nick Weldin (O'Reilly). Copyright 2012 Michael Margolis, Nicholas Weldin, 978-1-4493-1387-6.

 b)  Go to "http://xx.xxx.xx.xx:8081/" or whatever is appropriate relative to how you set things up. Hopefully at this point you see a pretty basic Web page that has buttons for turning on and off the LED and making the servo go forward, backward, or stop.  The code I supplied also imports a live video feed from an IP camera but this functionality is commented out.  Perhaps in the future I will detail how to set that up in another post.



STEP 5: BUILD THE CIRCUIT 


The circuit I built is shown below.  This circuit depiction was drawn using a great tool called Fritzing.  This is pretty self explanatory.  The resistor is a 220ohm resistor.






















<adventures in hacking etsy seo>
Shop
Chicago Laser Cut
Coaster Blog
</adventures in hacking etsy seo>