Monday, 20 April 2015

ESP8266 Setup

ESP8266.

i'm using ESP-01 Version


Hardware pinout



Normal mode operation

Normal boot from flash, normal working mode
  • VCC- 3.3 ONLY! draws 20mA-250mA
  • GND-..
  • RX- connects to TX of arduino or similar controller
  • TX- connects to RX, ditto above
  • GPIO0/2- general purpose in out
  • RST- reset (LOW = reset active)
  • CH_PD- chip power down i.e. (LOW = power down active)
  • Red LED- power
  • Blue LED- status
Note it has been said that the last 4 pins must be attached to VCC, however Great Scott the youtuber has had success with only the CH_PD attached to VCC.


Firmware

Needed a ttl to usb adaptor very cheap 1-2 pounds- i prefer the cable as its easier to work with. 

Following this tutorial (and for updating the firmware this great Video from Kevin Darrah- check his channel out!) i will update the firmware using a USB - TTL cable, i'm powering the ESP with the arduinos 3.3v and ground although the arduino wont give the max current the ESP will take it will be enough for updating the firmware (just a bit slower). the green TX of the TTL cable goes to the RX of the ESP and the white RX of the TTL to the TX of the ESP.

Flash mode pin config

The other side of the cable im holding is USB and goes to ...the computer.
Im only using the power form the arduino here.
Note the shared ground. 




  • VCC- 3.3 from arduino
  • GND- from arduino also shared with the TTL cable
  • RX- connects to TX of TTL (green)
  • TX- connects to RX of TTL (white)
  • GPIO 0- set LOW
  • GPIO 2- set HIGH
  • GPIO 15- set LOW OR HIGH?! (SDM model)
  • RST- reset HIGH 
  • CH_PD-  HIGH


  • When the ESP is connected up- with power then connect to the computer. Before flashing with the software on the tutorial, make sure that you have updated the driver for the usb cable, goto devices and printers and auto update the driver. Now you should be able to flash the device.

    Follow the video and blog!

    And Then?

    if you have followed the tutorial, and have flashed the chip with new firm ware, we can now test it. Open the arduino IDE and select the com port that your ttl cable is connected to, open the serial monitor and try some commands.

    Some chips are already set to work at 9600 baud rate mine was, if not you might have to try 
    115200 and possibly others. Set auto scroll and "Both NL & CR"

    • AT
      • a simple test it should return "OK"
    • AT+RST
      • resets the board returns "[System Ready, Vendor:www.ai-thinker.com]" could fscanf or read for this line to ensure it has been restarted. (changed from firmware version to version)
    • AT+GMR
      • tells you the firmware its running
    • AT+CWMODE=?
      • tells you what modes it will accept: can be..
      • a device on the network
      • an access point- can log into it setup a password and ssid (completely stand alone device)
      • both
    • AT+CWMODE=1
      • changes mode 1-3
    • AT+CWMODE?
      • current mode
    • AT+CWLAP
      • displays wifi points
    • AT+CWJAP="SSID wifi name","password"  
      • connects to WIFI
    • AT+CWJAP?
      • check to see if connected to WIFI
    • AT+CIPMUX=1
      • setting it to accept multiple connections, required for the tcp connection to the internet.
      • Must always set the every time device is powered down!!!
    • AT+CIPMUX?
      • current mode
    • AT+CIPMODE=0
      • not data mode (= 1 is possible to set data streaming mode)



    And Then?

    So now we can connect to a wifi network and set the ESP to different modes.

    In my next post i'm going to have examples of getting data from the internet using the last two links under useful Reference Material. Here for a video

    Useful Reference Material

    Youtube

    Kevin Darrah- Just go there!
    Great Scott!- Lots of links in the info box (under the video)
    Julian Llett- Alot of interesting videos, lots of iot stuff
    AllAboutEE- Same as above

    Yahoo Query Language-
    Yahoo Query Language tutorial-

    Friday, 17 April 2015

    8x8 Led Matrix using Max7219 IC


    The Board

    The Maxim 7219 IC

    Info here

    The Library (LedControl)

    info here

    The Code





    Notes

    Can be daisy chained..

    setup functions

    void setup()
    {
      lc.shutdown(0,false);  // Wake up displays

      lc.setIntensity(0,1);  // Set intensity levels 1-15

      lc.clearDisplay(0);  // Clear Displays
    }

    lighting individual leds

    /* 
     * Set the status of a single Led.
     * Params :
     * addr  address of the display 
     * row   the row of the Led (0..7)
     * col   the column of the Led (0..7)
     * state If true the led is switched on, 
     * if false it is switched off
     */
    void setLed(int addr, int row, int col, boolean state);

    example
    //switch on the led in the 3'rd row 8'th column
    //and remember that indices start at 0! 
    lc.setLed(0,2,7,true);   
    //Led at row 0 second from left too
    lc.setLed(0,0,1,true);   
    delay(500);
    //switch the first Led off (second one stays on)
    lc.setLed(0,2,7,false);



    Control all leds in a row

    The setRow(addr,row,value)-function takes 3 arguments. The first one is the already familiar address of our device. The second one is the row that is going to be updated and the third one the value for this row.

    Here is the signature of the method :

    /* 
     * Set all 8 Led's in a row to a new state
     * Params:
     * addr  address of the display
     * row   row which is to be set (0..7)
     * value each bit set to 1 will light up the corresponding Led.
     */
    void setRow(int addr, int row, byte value);

    example
    //include this file so we can write down a byte in binary encoding
    #include <binary.h>

    //now setting the leds from the third row on the first device is easy
    lc.setRow(0,2,B10110000);

    Ref websites 

    http://playground.arduino.cc/Main/LedControl
    https://brainy-bits.com/tutorials/how-to-control-max7219-led-matrix/


    Thursday, 22 January 2015

    Adjustable DC voltage using Lm317

    Intro

    I need a separate supply to drive servos for a robot arm i'm building. i'm using a 10k potentiometer and in the examples they use 5k, i found with the 10k potentiometer the voltage would only change in the lower 1/4 of the potentiometer (hard to select a particular voltage). I swapped out the 220 Ohm resistor recommended and used two 500 ohm resistors in series, now the whole of the potentiometer varies the output voltage.

    Useful examples
    http://www.circuitsgallery.com/2012/11/variable-power-supply-circuit.html
    http://www.eleccircuit.com/my-first-variable-dc-power-supply-1-2v-to-30v-1a-by-lm317/

    Data Sheet
    https://www.fairchildsemi.com/datasheets/LM/LM317.pdf


    headers are for Vin and Vout
    two resistors in series





    Thursday, 2 October 2014

    Light Following Robot

    Light Following Robot Using 555 Timers.


    I actually made this towards the end of March, i became interested in using integrated circuit and micro chips to make stand alone projects as they are cheaper than using an arduino for each project.

    There are two configurations for 555 timers mono stable and astable. For this project monostable is used. A great website explaining how they work.


    Monostable Operation

    "Unlike the astable, which has two unstable states and so continually switches from one to the other and back again, the monstable has one stable state and one unstable state.
    When triggered by a suitable pulse at its input (pin 2) it switches from its stable state, in which the output is low, to its unstable state where its output is high. This state exists for a time controlled by the values of R1 and C1, and at the end of this period the output switches back to its stable (low) state. Its primary use is therefore to produce a set time delay, initiated by an input pulse."


    Quote and image taken from http://www.learnabout-electronics.org/

    Building The LFR

    I followed this instructables it was the most simple one i could find, there are other tutorials out there that use potentiometers to set the sensitivity of the LDR's and hence the speed of the motors.




    Conclusion

    The idea worked however the LFR didnt really move.. i didnt have proper wheels, i cut some out from cardboard. Also the fact i didn't use motors with gear boxes and gave the motors more voltage than they needed resulted in not much torque.

    For my first play with 555 timers i am still happy with the out come. Ultimately i decided that having a mobile platform that i could add sensors to and program would be a better use of my time and didn't continue with it.

    Sunday, 21 September 2014

    433Mhz RF Transmitter and Receiver

    433Mhz RF Transmitter and Receiver.


    I wanted a cheap wireless solution, these are great at little over a pound each. 
    This is a great instructables on them with all the specs. Limitations are that they easily loose connection with each other, and don't really have enough power to go through more than one wall (on 5v) a max range of 100 M can be achieved with LOS (line of sight) also the direction of the antenna greatly affects performance.


    Virtual Wire

    The VirtualWire library allows you to easily communicate over RF. Official VirtualWire Documentation (PDF).


    Test project

    I wanted to control a coffee machine using these the idea was to have a button on my desk with an RGB LED, off: the LED would pulse red, brewing: the led would stay yellow and ready: the LED would pulse green.

    First prototype: got the led to work correctly with me pushing the button it would cycle through the colors no problem.

    Second prototype: Modified the example Tx and Rx code from virtual wire library to send a 1 then 0 with a second gap in between. added relay to control coffee machine. 

    Third prototype: combined both codes into one found that the LED wasn't working as expected it wouldn't display certain colors and i reasoned it was because the Tx part of the code being constantly sent with a small delay- this delay affected the PWM of the LED. To make it work a micro controller able to run two sets of code at the same time would be needed. But this expense is a little overkill for a simple remote coffee machine.

    Forth prototype: i simplified the user experience to a simple on/off, green/red operation.
    however the leds flash briefly, assume this is when data is being Tx.

    Im not going to use these to remotely control my coffee machine as the connection is unreliable and unable to reach the distance to it. I'm going to test these and see if i have better luck, also i need a way of getting 5-12 V from the mains to power the Rx. 


    Hardware Connections

    Rx Signal Wire to D12

    Tx Signal Wire to D12



    Code

    As i was only sending 1 or 0 i changed the following line in the set up. This is an array that holds the data you want to Tx.

    char Sensor1CharMsg[2];

    This line converts an integer array to a character array.

     itoa(ButtonData,ButtonCharMsg,10);
     
    Great information on converting CHAR to INT and vice versa.

    Tuesday, 3 June 2014

    Writing A Class

    Writing A Class In Processing

    As I'm not a programmer my understanding of the lingo needs improving I decided to investigate it. This tutorial by Daniel Shiffman (lots of good stuff on his website) helped me understand how they work.

    Get to the chopper!

    So me and a friend Micheal were drinking a few in my room and he suggested we make an app that when the button is pressed a random jpeg is displayed along with an mp3- we didn't get that far, but the next day i looked over it and decided to make it work but i would use classes.

    Say cheese!

    The Arnold app

    All the libraries i used should be included with processing. A problem i couldn't work out is that i wanted to be able to be a bit "trigger happy" with the mouse button, So that if the user didn't like the mp3 being played they could simply click and a new picture and mp3 would be played. I couldn't figure it out and we think its something to do with having one audio player object, having more would overkill for a small app. The solution would be to find a new library with better features and use something "better" like Python.

    Multiple Serial Ports

    Exploring Multiple Serial Ports Using Arduino Mega.


    I searched around for this because i will need to use it in future projects, at the moment i'm gearing up to build a mobile platform- wouldn't it be nice if it could map a room using sonar data... Anyway i found this excellent blog that explains it nearly perfectly apart from the TX to RX bit in step one, just beware, if you don't know what i'm on about I've made a comment at the bottom of his post.

    Using a USB to serial TTL cable allows another serial port to be connected to a PC from the mega. 

    USB To TTL Cable 

    The mega has 4 possible ports to utilize. The green is TX and should be connected to RX on the board the white is RX and should be connected to TX on the board, red is power and is optional (5V external) and black is ground. the USB is simply connected to a port on the PC.

    Ive put together a sketch that reads an LDR and prints the value to one serial port whilst the other port is used to keep track of when an led (the on board one connected to pin 13) is turned on and off using a button.

    Resistors 10K (theres one behind the LDR)

    To view two serial monitors in the arduino IDE open a fresh arduino program and set that to the serial port of your cable, or use Tera Term.

    Com7 Showing LDR Values Com9 showing that switch is off


    Saturday, 5 April 2014

    Bluetooth RGB LED

    RGB LED using serial over bluetooth


    Im using a HC-06 bluetooth module, its the same coding as sending data over serial but the com port is changed to the bluetooth port.

    I set up a GUI with processing using the control P5 library which sends the values to the bluetooth COM port.

    Desktop App


    Module to Arduino RX to TX and Vice Versa



     

    Saturday, 29 March 2014

    Xbox Pad

    Xbox pad

    This is something me and Ben worked on using the procontrol library he found to get and use values from the xbox pad.
    Eventually he wants to use this to control an RC plane and the camera on it!


    Using a pitch, yaw, gimbal to demonstrate.





    Wednesday, 12 February 2014

    Solar tracker

    Solar tracker 


    Update..

    Its been a while! ive got a few more projects that im working on. Im looking into building a balancing two wheeled robot, the chip im using is a MPU-6050 6-axis accelerometer/gyroscope which im having trouble getting my head around.. i found code to get values from it ive just got to find a suitable project to demonstrate it, i am also in the process of building a P.C.

    I was interested in this because the code can be used for a line following robot, also for solar panel applications.

    Components

    A servo
    Bread board
    Cardboard and tape to separate the two LDR's
    2 LDR's
    Two resistors, im using 550 ohms
    Arduino
    Wires


    Code

    The voltage received from the LDR's is compared with each other with a tolerance of 10 added, this is to stop the servos from jittering when say a cloud passes over one of them. If one voltage is bigger than the other the servos will move in 1 degree increments untill they are equal.

    The Circuit


    The left LDR is connected to A1 the right to A2, between these connections is a resistor connected to ground, with the other leg of the LDR's connected to 5V.

    Conclusions

    The positioning/angle of the LDR's really affect the accuracy of the system, and should be as symmetrical as possible.




      

    Saturday, 21 December 2013

    Sound Sensor with Relay

    Creating a "clap on" "clap off" light switch


    Warning!

    Because we are using mains power i feel i should give a little warning, the picture below shows cut wires with masking tape covering them, masking tape is not enough protective insulation! This was a quick test done in the middle of the night, as you can probably tell from both wires being cut!

    Components

    A strange sound sensor i found on amazon code HOT UK05, couldn't find a data sheet for this and hardly any information.

    A Cheap version of a SainSmart relay module (4 channel).

    An LED for debugging.

    And a lamp you can cut the wires to.

    Sound sensor

    I set the sound sensor as a digital input and adjusted the sensitivity using the onboard potentiometer. That way when sound was detected above a certain threshold the pin was set low and this lit the LED up.

    Relay module

    Heres a really good website with lots of information about relays.

    The Circuit


    Conclusions

    Using the sensor as a digital input it only has two states, on or off, if i wanted more accurate readings and control i would have to use it as an analoge input.

    After programming this i feel alot more confident about checking states, last states then toggling a switch.





    Wednesday, 18 December 2013

    LCD Display


    Displaying two variables on a SainSmart LCD keypad shield

    Intro

    Displaying information on an LCD display is something i want to use in future projects.
    I am trying to create a menu using the buttons on the shield but this is a little above my programming level at the moment. 

    I could have made a simple menu where if i held "down", temperature is displayed or "up", the light level is displayed, however i want to create a "Real Menu" using arrays to store the different things to be displayed on the LCD and counters to control where we are in the menu and what is to be printed to the LCD.

    The circuit


    Code
    Awesome code showing a menu
    Good advice
    Wiki



    Monday, 2 December 2013

    PIR and Light Sensor to LED


    Using two variables to control an event, in this case turning an LED on.

    Automatic light

    The Plan

    Using a photo resistor and a proximity sensor i want to recreate the automatic light!

    Photo resistor

    When placed in darkness resistance is high and vice versa.
    Used in a voltage divider circuit. We analog read the pin giving a reading between 0 and 5 volts which is then assigned a digital value between 0 and 1024. A great video on voltage dividers.



    a voltage divider circuit

    PIR

    Stands for Passive infrared sensor (HC-SR501) 

    Left pot. Adjusts sensitivity,  clockwise more sensitivity and vice versa

    Right pot. Controls amount of time (delay) between movement and re-trigger i.e. when set to mid point the time between is 5 seconds. This is only useful if not using a micro controller,  however when using a micro controller the delay can be programmed. A more in depth explanation on how they work here. 


    PIR sensor

    The circuit


    Conclusions

    A relay could be wired up and this circuit could be used to control a light with more power.


    Sunday, 17 November 2013

    Ultrasonic distance sensor

    The aim of this session is to become familiar with the HC-SR04 distance measuring sensor and have it control a servo.

    Original code taken from here

    Findings...

    So wired it up and pasted the code in... 

    It worked, its only really accurate up to 50 cm's (possibly because of the material it was reflecting off, it was pointed towards my window and a curtain) and the "wall" a of piece of paper i was using to test the distances must be at right angles to the sensor otherwise you get a wrong value . How it works is explained here.  


    Add a servo...

    When i added the servo it would jump around a lot because of the random values returned from the sensor. I wanted a smooth motion i.e. as an object is brought closer to the servo, the servo would move in one direction and vice versa.

    How to make it smooth...

    I found a smoothing code in the arduino IDE examples i used this to average the values from the sensor so as an object is brought closer to the sensor the values sent from it dont jump from one to another causing the servo to move to quickly from one position to another. I also multiplied the averaged value (the distance in cm) by 1000 then increased the scale to map it with the servo, this made the servo move even smoother. 

    The circuit


    The three wires leading off go to the servo 

    Conclusions

    This could be used for obstacle avoidance, proximity applications etc.
    The readings could be made even more accurate by adding a temperature pin and changing the value for the speed of sound through the air and using more code.


    User manual for HC-SR04
    My Code for Arduino ive left the comments as they a relevant if not related.




    Wednesday, 20 March 2013

    To infinity and beyond!

    So building on the thermometer, i want it to be displayed on a 4 digit 7 segment display... i want to use a shift register to control the LEDs.. but first im going to have to learn what they are and how to use them.

    This is from the arduino website but is condensed into my own report

    74HC595 Shift Register

    "8-bit serial-in, serial or parallel-out shift register with output latches; 3-state."

    So this shift register is 8 bit, it can access 8 bits of information in a single machine instruction. Because each bit has two possible states "on" and "off" and there are 8 bits, this gives 256 possible combinations... e.g. 2*2*2*2*2*2*2*2 = 2^8


    Serial output

    Uses "synchronous serial communication" which means we can pulse one pin on and off communicating a data byte, bit by bit, the bits are separated by pulsing the clock pin.

    Parallel output

    "asynchronous communication" uses the Serial.begin() function of arduino, the data rate must be set on the sender and receiver. When the whole byte (8bits) are received the register deals them out to each output pin, then they are executed at the same time.


    Connecting another

    There is an option to use the serial out pin the transmit the serial information out to another register unchanged. Meaning you can transmit 16 bits of information where the first 8 will be passed though the first chip and expressed in the second.


    3 states

    Means HIGH, LOW and high impedance. This means the entire chip is set to low current, high voltage. Its uses include an LED array that might need to be controlled by different micro controllers depending upon its setting.

    The Pin-Outputs are.....


    PINS 1-7, 15Q0 " Q7Output Pins
    PIN 8GNDGround, Vss
    PIN 9Q7"Serial Out
    PIN 10MRMaster Reclear, active low
    PIN 11SH_CPShift register clock pin
    PIN 12ST_CPStorage register clock pin (latch pin)
    PIN 13OEOutput enable, active low
    PIN 14DSSerial data input
    PIN 16VccPositive supply voltage

    What happens inside the chip?

    When the clockPin (SH_CP) switches from LOW to HIGH the shift register reads the state of the dataPin (DS). When the shift register is full the latch is switched to HIGH this sends the information to the storage register then to the outputPins.. The rabbit hole gets deeper... 



    Creating a circuit




    Turning it on

    GND (pin 8) to ground
    Vcc (pin 16) to 5V
    OE (pin 13) to ground
    MR (pin 10) to 5V

    Connect to Arduino

    DS (dataPin) (pin14) to Arduino DigitalPin 11
    SH_CP (clockPin) (pin 11) to Ardunio DigitalPin 12
    ST_CP (latchPin) (pin 12) to Arduino DigitalPin 8

    So whats next..?

    Well the code in example two looks interesting i can type a number into the serial and the corresponding LED will illuminate( Pin 15 is 1). I can see how the hardware side works, now ive got to work on the programming..


    Phillip`s data sheet for 74HC595