Tuesday, 8 November 2016

Add ability to measure GPS data to the robot

For this I am using an item entitled "GY-NEO6MV2 GPS EEPROM MWC APM2.5 For Arduino" on ebay.

Having connected it to my USB to TTL converter and a 3.3V source I ran up the u-blox application u-center and got the following out in the text console:
15:21:06  $GPRMC,152106.00,A,5140.74757,N,00117.62006,W,0.342,,081116,,,A*6A
15:21:06  $GPVTG,,T,,M,0.342,N,0.633,K,A*20
15:21:06  $GPGGA,152106.00,5140.74757,N,00117.62006,W,1,03,4.08,64.0,M,47.1,M,,*73
15:21:06  $GPGSA,A,2,02,06,09,,,,,,,,,,4.20,4.08,1.00*05
15:21:06  $GPGSV,1,1,03,02,40,300,33,06,64,247,36,09,84,142,33*4D
15:21:06  $GPGLL,5140.74757,N,00117.62006,W,152106.00,A,A*79
Message Name Meaning
$GPRMC Recommended Minimum data
$GPVTG Course over ground and Ground speed
$GPGGA Global positioning system fix data
$GPGSA GNSS DOP and Active Satellites
$GPGSV GNSS Satellites in View
$GPGLL Latitude and longitude, with time of position fix and status
I need to use an esp specific version of SoftwareSerial as I do not want to use the main rx,tx pins of the esp-12f. To decode the messages from the gps device read on pin14 I use a TinyGPS object

//gps serial 
TinyGPS gps;
// rx 14, tx 12 - brown
SoftwareSerial gpsSer(14,12, false, 256);

loop{
...

while (gpsSer.available()){
    if(gps.encode(gpsSer.read())){
      long lat, lon;
      unsigned long fix_age, time, date, speed, course;
      unsigned long chars;
      unsigned short sentences, failed_checksum;
       
      // retrieves +/- lat/long in 100000ths of a degree
      gps.get_position(&lat, &lon, &fix_age);
       
      // time in hhmmsscc, date in ddmmyy
      gps.get_datetime(&date, &time, &fix_age);
       
      // returns speed in 100ths of a knot
      speed = gps.speed();
       
      // course in 100ths of a degree
      course = gps.course();

      Serial.print("Latitude:");
      Serial.print( lat);
      Serial.print(" Longitude:");
      Serial.println( lon);
      
      break;
    }
  }
...
}

Saturday, 29 October 2016

Adding OTA capability to my robot sketch

Follow the guide here
If you need to remove an old version of Arduino before installing the required version make sure to restart your pc before using the new version.

Output  from Arduino IDE on request to upload:
Sketch uses 256,387 bytes (24%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 36,264 bytes (44%) of dynamic memory, leaving 45,656 bytes for local variables. Maximum is 81,920 bytes.
python.exe C:\Users\edwin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/espota.py -i 192.168.1.95 -p 8266 --auth= -f C:\Users\edwin\AppData\Local\Temp\arduino_build_442534/esp8266_robot.ino.bin
16:19:05 [ERROR]: No Answer
python.exe C:\Users\edwin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/espota.py -i 192.168.1.95 -p 8266 --auth= -f C:\Users\edwin\AppData\Local\Temp\arduino_build_442534/esp8266_robot.ino.bin
Authenticating...FAIL
16:19:09 [ERROR]: Authentication Failed
python.exe C:\Users\edwin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/espota.py -i 192.168.1.95 -p 8266 --auth=123 -f C:\Users\edwin\AppData\Local\Temp\arduino_build_442534/esp8266_robot.ino.bin
Authenticating...OK
Uploading...................................................................................................................................................................................

Output on com port during upload:
lpls$|nd.......
WiFi connected
Server started
192.168.1.95
Start
Progress: 100%
End
 ets Jan  8 2013,rst cause:2, boot mode:(3,7)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v3de0c112
@cp:0
     ld
       .......
WiFi connected
Server started
192.168.1.95

Thursday, 13 October 2016

First exploration of atTiny85

I thought that I could use an atTiny85 as a lipo low voltage reporter.


Using ArduinoUno as ISP and first sketch for atTiny

I used the Arduino Uno as an avrisp to program the atTiny85 following the guide in http://highlowtech.org/?p=1695. Note that before using the Uno as a programmer you need to install  the sketch ArduinoIsp on itself. Install for this step you set the board to ArduinoUno. After that load any sketch e.g blink with pin13 changed to 0 , set the board and processor to attiny85.

Another great tutorial is at https://www.hackster.io/arjun/programming-attiny85-with-arduino-uno-afb829


Pinouts - thanks to https://engineerzero.wordpress.com/2013/05/07/attiny-4585-pin-conventions-for-arduino-ide-sketches/

Serial Communications

atTiny85 does not have dedicated serial comms capability but serial comms can be done using SoftwareSerial. See http://www.instructables.com/id/ATtiny85-ATtiny84-Analog-Pins-Serial-Communication/step3/Using-SoftwareSerial-for-Communication/

Note that to monitor rx,tx either connect the pins 2 and 4 to tx, rx on an ArduinoUno, after downloading blink sketch to return to normal behaviour or use a usb serial adapter. I find that if using the Arduino you need to connect vcc to 3.3 v otherwise the serial communication is noisy.


Reading a voltage 

  val = analogRead(1); // read from ADC1 - pin7
  val = analogRead(2); // read from ADC2 - pin3
  val = analogRead(3); // read from ADC3 - pin2

Note that you cannot use the same physical pin for analogRead and SoftwareSerial.

The result is 0 to 1023 with 1023 representing 100% of vcc. So using Vcc of 3.3 and applying 1.1v to the adc the value of val is 342.  

Using the internal voltage reference

See the following links:
http://www.re-innovation.co.uk/web12/index.php/en/information/electronics-information/accurate-voltage-measurement

To read using the internal 1.1v reference simply add :
  analogReference(INTERNAL1V1);
to the setup function of the sketch.

However the actual internal voltage can be off by 10%.
My current atTiny85 returns 490 when measuring 0.5v that means Vinternal is 1023/490 * 0.5 = 1.04 rather than 1.1. Now you could write the actual internal voltage into a chip specific sketch or save the value in the EPROM for other sketches to read.

Fuses and preserving EEPROM and system clock

fusecalc

use of eeprom


Also you need to make sure the ATTiny is set to preserve EEPROM during upload with the ISP, this is done with the fuse settings. You need to look for a tutorial on fuse calculators for the AVRs. To set the EESAVE you need to set the High fuse to 0xD7, you can change this in the boards.txt file. Here is a fuse calculator.



From Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf
The CKDIV8 Fuse determines the initial value of the CLKPS bits. If CKDIV8 is unprogrammed, the CLKPS bits will be reset to “0000”. If CKDIV8 is programmed, CLKPS bits are reset to “0011”, giving a division factor of eight at start up.
The device is shipped with CKSEL = “0010”, SUT = “10”, and CKDIV8 programmed. The default clock source setting is therefore the Internal RC Oscillator running at 8 MHz with longest start-up time and an initial system clock prescaling of 8, resulting in 1.0 MHz system clock.

As CPU speed is not an issue I will use internal 1Mhz rather then  8MHz. This is done by programming CKDIV8 which means setting top bit of lfuse to 0.    The internal oscillator of 8Mhz is selected by setting the CKSEL bits to 0010 which is the default.

Reading and Writing the EEPROM using AVRDUDE

First cd to the folder containing avrdude.exe:
cd C:\Users\edwin\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino6/bin
c:

To read the eeprom to file eedump.hex:
avrdude  -C../etc/avrdude.conf -v -pattiny85 -cstk500v1 -PCOM5 -b19200 \
-Ueeprom:r:eedump.hex:i

To write the contents of eedump.hex to eeprom:
avrdude  -C../etc/avrdude.conf -v -pattiny85 -cstk500v1 -PCOM5 -b19200 \


-Ueeprom:w:eedump.hex:i

Monday, 12 September 2016

Driving motors using the Adafruit Motor Shield and the esp-12f


IMPORTANT.
The Adafruit Motor Shield normally gets its logic voltage from the Arduino Uno which runs at 5V,  and the ESP-12f uses 3.3V so you may think that a logic level converter is required and a 5V source. However the motor shield I2C and drive system works fine with connecting Vin to the 3.3V used by the esp-12f. The motors are power separately and you need to remove the Vin jumper.

The motor shield and esp-12f communicate using I2C.
The pins on the ESP-12f are GPIO4( blue wire on my breadboard) is SDA and GPIO5 ( orange wire on my breadboard) is SCL.
The pins on the motor shield are as for  Arduino Uno as it i a shield, That is pin A4( analog 4) for SDA and pin A5(analog 5) for SCL. Note that similarity in numbers between the two devices.

The I2C address of the motor shield is hardcoded in the  library as 60.

Interfacing with the robot using a Web Browser

I next followed the tutorial in https://learn.adafruit.com/build-an-esp8266-mobile-robot. The simplest way is to clone the example code git repo into the Arduino sketches folder and
  1. eps8266_robot.ino - set the ssid and password appropriately, compile and upload
  2. scripts.js - set the ip address of the esp8266 
Then simply open the demo.html and you're off.

Thursday, 8 September 2016

Reflashing the firmware of esp-12f

I basically followed the notes in Category:ESP8266_Firmware_and_SDK#Default_Firmware_.28ESP-12F.2C_and_the_series.29
I chose to use the Default firmware V1.3.0.2_AT_Firmware.bin.zip and the ESP_DOWNLOAD_TOOL_V2.4.exe with the parameters set as in the figure given in the first url.
Make sure you connect GPIO0 to ground and power on the esp-12f  before starting the download.
My first attempt failed with message "Open Port Failed"; which was because I had the port open from a Serial Monitor window.


Now make GPIO0 float and restart the esp-12f.

To test the new firmware I used Arduino IDE's Serial monitor and sent AT+GMR which gave the output below.




Now to try out some other firmwares!

D:\edwin\Downloads\V2.0_AT_Firmware(ESP)\v2.0 AT Firmware(ESP).bin
Fatal exception (0):
epc1=0x40201c04, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
This leads to output on baud 74880:


 ets Jan  8 2013,rst cause:2, boot mode:(3,7)
load 0x40100000, len 816, room 16
tail 0
chksum 0x8d
load 0x3ffe8000, len 788, room 8
tail 12
chksum 0xcf
ho 0 tail 12 room 4
load 0x3ffe8314, len 288, room 12
tail 4
chksum 0xcf
csum 0xcf
2nd boot version : 1.2
  SPI Speed      : 40MHz
  SPI Mode       : QIO
  SPI Flash Size : 8Mbit
jump to run usererror user bin flag, flag = c
user code done
Done load empty sketch:

on baud 74880
Fatal exception (0): 
epc1=0x40202770, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

Wednesday, 7 September 2016

Using Arduino IDE for programming the ESP-12f

After the steps described in using-esp-12f-for-remote-control.html I decided to try to program the actual firmware using the Arduino IDE.  How to do this is described in many places e.g. esp8266-thing-hookup-guide/installing-the-esp8266-arduino-addon.


Use of GPI0

However I kept having failures when trying to upload the sketch. The reason was that to upload the firmware over serial I need to connect GPIO to ground rather than leaving it floating for actual running the saved firmware.


Picture of GPIO0, GPIO2 and GPIO15 pins

Running a webserver on esp-12f

esp8266-web-server-with-arduino-ide/

Resetting the ESP-12f firmware

Tuesday, 6 September 2016

Using an ESP-12f for remote control

It may be possible to get rid of the Xbee and arduino approach and replace it with a single ESP-12f in the robot and a browser app to control it.

Parts list:
Perfect USB to TTL Converter CH340G STC 5V/3.3V 6Pin UART Serial Adapter Module from ebay for £0.99
Picture of B- USB to TTL UART Module CH340 3.3V/5V Serial Converter 

Note that I left the jumper across the OFF and 3.3v pins so that RX,TX are 3.3v compatible.

ESP8266 ESP-12F WiFi Wireless Wi-Fi Module + Vertical Breakout Board, UK, FAST for £5.85. Yes a bit expensive but I liked the breakout board.



3.3V power supply.


Connecting these together is given in many places.The figure below comes from http://www.instructables.com/id/Getting-Started-with-the-ESP8266-ESP-12/Picture of Make the connections

To send AT commands use the Serial Monitor in Arduino IDE with baudrate set to 115200