Author Topic: Another wireless networking option: ESP8266  (Read 6127 times)

alobo

  • New Member
  • *
  • Posts: 33
    • View Profile
Another wireless networking option: ESP8266
« on: June 15, 2015, 09:56:21 PM »
I stumbled upon this chip a couple of days ago, the ESP8266 Serial-to-WiFi thingamabob.

Seems interesting, and considering the wait time on the Flutter Wireless that I'd posted about earlier (they've started shipping! a good sign for a kickstarted project), this is plenty cheaper and has a pretty established community of users, it appears.

It's 3.3V only, with a built in RTC and can attach to existing WiFi or act as its own hotspot from what I've read so far. At $5 a pop (or less), that ain't bad.
« Last Edit: June 15, 2015, 10:30:39 PM by alobo »


Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #1 on: June 16, 2015, 07:23:53 PM »
I was just thinking about that flutter wireless project a couple of weeks ago actually. It's nice to see that stuff coming down in price. In my case at least, being able to set up heliostats and sun trackers to operate wireless would definitely simplify set up. It just tends to bring the cost up a lot. I will have to try these chips out sometime.

Thanks!


alobo

  • New Member
  • *
  • Posts: 33
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #2 on: June 16, 2015, 09:13:35 PM »
It seems at least a couple of people are working on using the ESP8266 to wirelessly upload code to microcontrollers. I found a Youtube video, but there was no link to the how-to. This guide seems the most clear, albeit not entirely simple.

alobo

  • New Member
  • *
  • Posts: 33
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #3 on: June 21, 2015, 09:26:53 PM »
A friend of mine suggested via Facebook, that the processor built into the ESP8266 can be programmed via the Arduino IDE. I'm looking now for the most up-to-date guide if there is one. EDIT: This looks like it.

Apparently it's a 32-bit processor with a fair bit of memory. According to Hackaday, "The processor by default runs at 80 MHz but can go up to 160 MHz, it has ~80kB DRAM (Data RAM), and ~35kB of high speed IRAM (Instruction RAM)." The chip itself has 16 GPIO pins, of which 10 are made available with the ESP-12 breakout board.

And my friend on Facebook quite temptingly noted: A Mega from Adafruit costs $45 and has 54 I/O with its 16MHzCPU and 256kB RAM; an ESP-12 board can go as low as $3 with 10 GPIO and its faster processor, so 6 of them would give you 60 GPIO, with every 10 pins having its own high-speed processor and more total RAM, for less than $20.

This is giving me ideas, considering the A4988 stepper driver chip is 3.3V compatible ... But for all I know might require a significant redevelopment of your tracker code, hahah. I'm not a very good programmer, but I just might give it a shot anyway just because why the hell not. ;D
« Last Edit: June 30, 2015, 09:42:08 PM by alobo »

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #4 on: June 23, 2015, 08:01:30 AM »
Being able to program the chip with the tracking code would definitely bring down the cost since you wouldn't need another chip for each tracker.

There probably would have to be some changes to the tracker code. That just seems to be how things are typically when moving to another platform, even when that platform is supposedly "Arduino Compatible". Of course, a lot of the code could be cut out and simplified since much of it is dedicated making it possible to control multiple machines.

I suppose you really only need the code that moves the motors on the ESP8266. So you would just send the altitude and azimuth angles and have the chip move the machine into position. The code that resets the machine would also probable be needed. Everything else could just be done on another microcontroller, or maybe a PC.

I might have to get one of these chips and give it a try. I'm trying to finish up some other projects first though. I can still try and help you if you get it started though if you'd like.


alobo

  • New Member
  • *
  • Posts: 33
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #5 on: July 24, 2015, 10:12:45 PM »
So I've started on this. I think the biggest obstacle is the BigNumber library; it doesn't compile directly for the ESP8266 and I'm not sure how to fix that. Apart from that, all I'd do is copy your code mostly verbatim (but ignoring the subroutines for multiple machine control). I'd have to adapt EEPROM and RTC codes and such for the ESP8266, but that seems to be relatively straightforward (at least according to the Github page).

I included the BigNumber library in an empty Arduino sketch configured for the ESP8266 (image attached), and compiling failed - I've attached the compiler output in a text file. The warnings / errors that show up are:

Warnings:
Code: [Select]
......
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c: In function 'bc_str2num':
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:1523:7: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
   ptr = str;
       ^
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:1548:7: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
   ptr = str;
       ^
.......

Errors:
Code: [Select]
.......
/root/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9/bin/xtensa-lx106-elf-gcc -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -L/root/.arduino15/packages/esp8266/hardware/esp8266/1.6.4-673-g8cd3697/tools/sdk//lib -L/root/.arduino15/packages/esp8266/hardware/esp8266/1.6.4-673-g8cd3697/tools/sdk//ld -Teagle.flash.512k.ld -o /tmp/build4714199143779152163.tmp/sketch_jul25a.cpp.elf -Wl,--start-group /tmp/build4714199143779152163.tmp/sketch_jul25a.cpp.o /tmp/build4714199143779152163.tmp/BigNumber/number.c.o /tmp/build4714199143779152163.tmp/BigNumber/BigNumber.cpp.o /tmp/build4714199143779152163.tmp/BigNumberMath/BigNumberMath.cpp.o /tmp/build4714199143779152163.tmp/core.a -lm -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig -Wl,--end-group -L/tmp/build4714199143779152163.tmp
/root/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /tmp/build4714199143779152163.tmp/sketch_jul25a.cpp.elf section `.text' will not fit in region `iram1_0_seg'
/tmp/build4714199143779152163.tmp/BigNumber/number.c.o: In function `_bc_do_compare$part$0$constprop$5':
number.c:(.text+0x230): undefined reference to `exit'
number.c:(.text+0x24b): undefined reference to `exit'
/tmp/build4714199143779152163.tmp/BigNumber/number.c.o: In function `new_sub_num$constprop$3':
number.c:(.text+0x288): undefined reference to `exit'
/tmp/build4714199143779152163.tmp/BigNumber/number.c.o: In function `bc_divide':
number.c:(.text+0xcb8): undefined reference to `exit'
/tmp/build4714199143779152163.tmp/BigNumber/number.c.o: In function `bc_raisemod':
number.c:(.text+0x1138): undefined reference to `exit'
/tmp/build4714199143779152163.tmp/BigNumber/number.c.o:number.c:(.text+0x1433): more undefined references to `exit' follow
/tmp/build4714199143779152163.tmp/BigNumber/number.c.o: In function `bc_sqrt':
number.c:(.text+0x14a0): undefined reference to `__ctype_ptr__'
/tmp/build4714199143779152163.tmp/BigNumber/number.c.o: In function `bc_str2num':
number.c:(.text+0x15fc): undefined reference to `exit'
collect2: error: ld returned 1 exit status
Error compiling.

Perhaps the warnings can be ignored, but from what I've been able to Google, the 'undefined reference' errors are related to some library not being included? I'm not sure how to pinpoint it.

EDIT: I've posted on the ESP8266 forums. Hopefully there'll be interest in this. The ESP8266 board could be configured to regularly get time updates over WiFi (my DS1307 RTC unfortunately drifts over a minute per week).
« Last Edit: July 24, 2015, 11:06:21 PM by alobo »

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #6 on: July 27, 2015, 07:04:08 AM »
It looks like the ESP8266 has a 32-bit CPU (unlike the 8-bit CPU on most Arduinos). It's possible that you don't even need the BigNumber Library. The only reason I had to use it is because it allows a 8-bit microcontroller to do double precision math.

Maybe try this code and see what the output is.

double test = 123.456789123456789;
Serial.println(test,20);


If it prints most of the numbers accurately, then the chip (or more accurately the compiler for the chip) is already set for double precision math. This would mean that the sun calculations could be programmed without the BigNumber Library.

If it only prints a little less than half of the numbers accurately, then I suppose the compiler would need to be modified, or perhaps you would have to find another one. I'm not sure though. This is an area of programming that I know very little about.

alobo

  • New Member
  • *
  • Posts: 33
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #7 on: July 29, 2015, 09:41:43 PM »
ESP8266 user martinayotte modified the BigNumber library to compile directly for the ESP8266 in the Arduino IDE (see the forum post). So this saves me from having to rewrite the equations (I'm afraid of messing up the variables and calculations, hahah). Perhaps it can be rewritten later to reduce the memory footprint of BigNumber, but for now it should work.  ;D

I've attached the modified library below for your perusal. The SunCalculations code compiles without a problem. I unfortunately seem to have damaged my ESP8266 and it's not responding. Waiting for a new one(s) to test the output.

I think some modifications need to be made to use the EEPROM library correctly with ESP8266 - both in terms of calling functions, and the EEPROM size: 512 bytes, as opposed to 1kB on the Uno and 4kB on the Mega.
There is a RTC library to control DS1307 and DS3231 RTC chips ... you may find it promising to go over the latest documentation for using the ESP8266 with the Arduino IDE, here. Almost all of the basic code is now interchangeable between Arduinos and ESP8266.

I've posted another question on the ESP8266 forums about getting access to the ESP8266's internal RTC via the Arduino IDE. If that can be achieved (and is accurate enough), then you can get rid of the external RTC, and all that needs to be added is a subroutine to regularly connect to WiFi and update ... and, done!
« Last Edit: July 29, 2015, 11:23:53 PM by alobo »

alobo

  • New Member
  • *
  • Posts: 33
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #8 on: August 01, 2015, 03:17:04 AM »
I tried that code snippet you posted, and the serial output:

double test = 123.456789123456789;
Serial.println(test, 20);

Serial output:
123.45678912345678668316

I presume that is good .... but I still don't want to have to rewrite all the sun calculations  ;D

I found that the BigNumber library compiles, and throws a few errors:

Code: [Select]
In file included from /home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:43:0:
/root/.arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/tools/sdk//include/c_types.h:80:0: warning: "TRUE" redefined [enabled by default]
 #define TRUE            true
 ^
In file included from /home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:39:0:
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.h:84:0: note: this is the location of the previous definition
 #define TRUE 1
 ^
In file included from /home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:43:0:
/root/.arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/tools/sdk//include/c_types.h:81:0: warning: "FALSE" redefined [enabled by default]
 #define FALSE           false
 ^
In file included from /home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:39:0:
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.h:85:0: note: this is the location of the previous definition
 #define FALSE 0
 ^
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c: In function 'bc_str2num':
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:1524:7: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
   ptr = str;
       ^
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:1549:7: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
   ptr = str;
       ^
In file included from /home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:43:0:
/root/.arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/tools/sdk//include/c_types.h:80:0: warning: "TRUE" redefined [enabled by default]
 #define TRUE            true
 ^
In file included from /home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:39:0:
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.h:84:0: note: this is the location of the previous definition
 #define TRUE 1
 ^
In file included from /home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:43:0:
/root/.arduino15/packages/esp8266/hardware/esp8266/1.6.5-947-g39819f0/tools/sdk//include/c_types.h:81:0: warning: "FALSE" redefined [enabled by default]
 #define FALSE           false
 ^
In file included from /home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:39:0:
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.h:85:0: note: this is the location of the previous definition
 #define FALSE 0
 ^
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c: In function 'bc_str2num':
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:1524:7: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
   ptr = str;
       ^
/home/works/Downloads/arduino-1.6.5/libraries/BigNumber/number.c:1549:7: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
   ptr = str;
       ^

However.
I wrote an empty sketch, and only included the BigNumber and BigNumberMath libraries.
It seems the problem lies in your "BigNumberMath" library. The code below compiles and uploads just fine:

Code: [Select]
#include <BigNumber.h>
#include <BigNumberMath.h>

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

void loop(){
DEBUGLN("loop", millis())
delay(500);
}

but, the ESP8266 does nothing after that, and if I reset it, goes into a loop outputting this error:

Code: [Select]
ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld

This error goes away if I comment out the BigNumberMath library.

I'll continue to ask on the ESP8266 forums, though. They may be able to help resolve this .... or else I may just have to rewrite the sun calculations.

If I have to rewrite it, how should I go about it? Is it as simple as replacing every instance of "BigNumber" with "double" and correcting the number syntax?
« Last Edit: August 01, 2015, 03:19:29 AM by alobo »

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #9 on: August 03, 2015, 11:41:24 AM »
Yeah you definitely don't want to try and rewrite all that. :)

I have the normal version of the calculations for a program I wrote in Processing. I put them in an Arduino program and attached it to this post.
The program does compile and give an output, but because it's running on an Arduino Uno, I'm sure it's inaccurate.

Hopefully it should run OK on the ESP8266. You should probably double check the output though. I wonder if the compiler still uses look up tables for the trig functions though even though the chip can do double precision math. If I remember correctly, the Arduino normally uses look up tables when doing trig functions. This would make the sun calculations less accurate. There may be a library or something that adds more accurate trig functions if needed, but I'm not sure.

Paul L

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #10 on: August 06, 2015, 08:30:42 PM »
hey alobo,

   sounds like you're making some progress porting it to the esp8266!  keep up the good work, and keep us all informed -  it's an interesting project and I'm interested in where you'll take it!

cheers,

Paul

alobo

  • New Member
  • *
  • Posts: 33
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #11 on: August 11, 2015, 02:04:14 AM »
Thanks Gabriel, your Processing sun tracking code worked! I'm still not entirely sure of its accuracy, though. I used the NOAA Solar Position Calculator to see, but it only reports the values to 2 decimal places.

I used these settings for both the online calculator and your program:
Latitude: 15.4989
Longitude: 73.8278
Timezone: +5 (It's actually 5.5 but I don't know if the calculations in your program account for that)
Time: 13:00:00 on Aug 1 2015
UseNorthAsZero = TRUE

NOAA
Azimuth: 284.06 clockwise from North
Altitude: 78.01 above the horizon
Arduino code
Azimuth: 121.194
Altitude: 84.792
Suggestions?

I don't see why the ESP8266 would use lookup tables to calculate when it's rather more powerful than an Arduino Mega - but it may be worth checking.
... Uh, how do I check that?  ;D


Long story short: I took out the BigNumber and Wire libraries, replaced the Sun Calculations with the Processing code you sent. Couple of small adjustments to the EEPROM read/write code, but otherwise unchanged. Changed pin numbers to correspond to appropriate ESP pins.
Basically, totally plagiarized every part of your program. But it runs on the ESP, compiled using the latest Arduino IDE 1.6.5! I'm using a ESP-12E board.

My major snag right now is, the MoveMachine code. I haven't yet connected any other circuitry - I just want it to compile and run through fully first. It seems that the ESP8266 accepts the code and runs through it relatively fine, up to the point where it moves the steppers. Specifically, in Functions.ino, at the function moveMotorWithAccel. There's a loop there that controls the acceleration of the steppers. It actually goes through that loop up to the point where it's supposed to reset the motors, and crashes throwing up a stack trace full of hex values which I have no idea how to interpret.
But, funny story: I threw in a few debug lines into the loop to see exactly at what point it was crashing, and it DIDN'T crash! No doubt the Serial output introduces a significant delay in the motor-stepping code, but why would the crashing happen at all, in that case, I wonder. What do you think?


I narrowed it down to the delayInMicroseconds, more or less. Without the debug code in the motor-stepping code, it kept crashing. So, I inserted a teensy little delay(0); into your delay function. Worked like a charm ... I hope. Now over the next couple of days I'll wire up my stepper drivers and see how well it tracks.

I also added a subroutine to connect to my WiFi and request time from an NTP server (plagiarized from one of the Arduino/ESP8266 example sketches). It connects to WiFi in just about 2 seconds - but it seems to have difficulty connecting to the Internet even though my computers on the same network have no issue. Oh well. I'll keep you posted as I figure it out.
« Last Edit: August 11, 2015, 05:00:44 AM by alobo »

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #12 on: August 12, 2015, 12:23:18 PM »
Hi Alobo,

If the program is accurate to two decimal places, then it is probably good enough. Not many people can build a machine that is more precise than that.
I didn't know that they had half time zones. I think that you could use 5.5 as the timezone just fine though. The timezone basically just converts the time from your time to GMT time.

Because the ESP8266 is using the Arduino IDE, it is worth double checking to see if anyone bothered to use the more accurate trig algorithms. It's possible that it automatically switches over, or it may be that the syntax needs to be changed or something. Probably the best way to be sure is to research it or ask someone. You could also just input a bunch of angles into one of the trig functions and double check the output using Google's calculator or something.

Replacing the delayInMicroseconds with delay probably will cause issues when running the stepper motors. Basically, regular delay cannot pause for a short enough time to make the pulses running the stepper motors fast enough to run the stepper motors run at any considerable speed.
I've cheated before by basically just having the processor do a calculation over and over a bunch of times which creates a short delay. It works, but you pretty much have to just do a bunch of experimenting to get the timing right.

It all definitely seems to be moving along doesn't it. :)

alobo

  • New Member
  • *
  • Posts: 33
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #13 on: August 12, 2015, 06:17:02 PM »
From the ESP8266 Arduino Github reference:

Remember that there is a lot of code that needs to run on the chip besides the sketch when WiFi is connected. WiFi and TCP/IP libraries get a chance to handle any pending events each time the loop() function completes, OR when delay is called. If you have a loop somewhere in your sketch that takes a lot of time (>50ms) without calling delay, you might consider adding a call to delay function to keep the WiFi stack running smoothly.

There is also a yield() function which is equivalent to delay(0). The delayMicroseconds function, on the other hand, does not yield to other tasks, so using it for delays more than 20 milliseconds is not recommended.


I didn't replace your custom delayInMicroseconds function (although that was my first idea). I only added the delay(0) into the end of it. No doubt it might cause a tiny slowing of the stepping code, but that's preferable to the program continually crashing lol


As for the trig accuracy, I'll see what I can find. The NOAA calculations and the ESP8266 values are not as close as I would expect - but that may be due to differences in the algorithm, perhaps, as opposed to precision? Let's see what comes up.

alobo

  • New Member
  • *
  • Posts: 33
    • View Profile
Re: Another wireless networking option: ESP8266
« Reply #14 on: September 09, 2015, 01:29:42 AM »
I've been super busy but I've made a little progress. I'll post my code once I've cleaned it up significantly - it's a horrible mess.

So if you haven't gone and got yourself an ESP8266 board yet, something's wrong with you.  ;D
There's a lot of choice, but I strongly recommend an ESP-12 or ESP-3 board. Either one is barely an inch square but has all the pins we need. The pin spacing, however, is 2mm rather than the 2.54mm (0.1in) of typical breadboards. You'll need to make an adapter or buy one. Also, probably important: There's only one ADC pin and it only registers 1V max (anything above 1V - up to 3.3v - registers as 100%). Something to be considered.

The ESP8266 can be programmed using the Arduino IDE directly, which is EFFING AMAZING. Unlike the Arduino which has a fixed programming speed (115200 baud) as I recall, the ESP8266 has an auto-adjusting programming mode that automatically adapts to the speed selection in the IDE. It supports up to 921600 baud easily. Programming is done in seconds.

---------------------------------------------------------------------------------------------

Software:
  • Download latest Arduino IDE (1.6.5 as of this post)
  • Open File -> Preferences and look for a box labeled "Additional Boards Manager URLs"
  • In this box, copy/paste the following line: http://arduino.esp8266.com/stable/package_esp8266com_index.json and press OK
  • Open Tools -> Board -> Boards Manager, it will take a sec to download updated information
  • Scroll to the bottom of the boards manager and click "Install" for the ESP8266 option. It will download and install the latest libraries necessary for the ESP8266 platform.
  • Once that is done, open the Tools menu again, and select
    • Board: Generic ESP8266 module
    • Flash mode: QIO
    • Upload speed: 921600
    • Port: (whichever port signifies your USB-Serial converter, just as the Arduino does)
The computer is ready!

Hardware:
Important: You will need a 3.3V power supply capable of up to 1A. Anything less is NOT going to cut it e.g. early model Raspberry Pi or Arduino 3.3V from a USB port. In my case I have a low-dropout regulator connected to a 12V supply.
It will also be very beneficial to use a 3.3V FTDI USB-Serial converter to program the ESP board, however you can get away with using any USB-Serial connection AS LONG AS the levels are converted to 3.3V and all grounds are tied together. The ESP8266 cannot tolerate any 5V connections.

Below is the pin mapping for the ESP-12, assuming it is mounted with the LED and metal enclosure are on top, with the antenna facing away from you.
Code: [Select]
                    ___ESP 12____
3v3 -> 10k -> RESET |           | TX / GPIO1
                ADC |           | RX / GPIO3
3v3 -> 10k -> CH_PD |           | GPIO5
             GPIO16 |           | GPIO4
             GPIO14 |           | GPIO0 <- 10k <- 3v3
             GPIO12 |           | GPIO2 / TXD1
        (RX)/GPIO13 |           | GPIO15/(TX) <- 10k <- GND
                VCC |3v3_____GND| GND
     
     GND -> SW1 -> RESET     GPIO0 <- SW2 <- GND

If you're worried about following that correctly, here's a proper schematic, and also a step-by-step checklist you can go over. You'll need four 10k resistors, 2 momentary push-button switches, and a capacitor. (Although if you buy a pre-made adapter board, the resistors / switches will likely be already soldered on).
  • VCC --> 3.3V; GND --> GND
  • RESET --> 10k  --> 3.3V
  • GPIO0 --> 10k --> 3.3V
  • CH_PD --> 10k --> 3.3V
  • GPIO15 --> 10k --> GND
  • Switch 1 connected between RESET and GND.
  • Switch 2 connected between GPIO0 and GND.
  • Capacitor between 3.3V and GND. I used a generic 100uF electrolytic capacitor that I had lying around, but even a 100nF will do according to schematics.
Switch 1 obviously is the Reset switch for the chip; Switch 2 is more important as it allows us to enter programming mode. In order to program the chip, GPIO0 must be held LOW during a reset cycle. So one would press both buttons but release the reset switch before releasing the GPIO0 switch.
The capacitor stabilizes power to the board when it sets up its WiFi connection.

Assuming that you have a 3.3V USB-Serial programmer, connect all the ground connections together, and connect its TX and RX pins to the ESP board's RX and TX pins, respectively. I made the mistake myself of connecting the TX and RX pins to each other and wondering why nothing was happening.

This is wrong:
TX --> <-- TX
RX <-- --> RX

This is correct:
TX --> --> RX
RX <-- <-- TX

You are now ready to program the ESP8266 ESP-12 board! (Ideally, anyway.) You can give it a test run by connecting a LED (with resistor) to one of the GPIO pins and uploading the basic Arduino "blink" sketch using that pin number.
---------------------------------------------------------------------------------------------
To get your Sun Tracker program working on the ESP8266, these are the steps I took, starting with the untouched Mega version of the program.
  • remove all references to the BigNumber library and replace the SunCalculations with the code you provided earlier in this thread.
  • remove any and all code referencing the MCP23017 I/O expander and the Wire library. The Wire library has been ported to the ESP, so it works, but we don't need it assuming one ESP8266 board per machine.
  • invert the LOW/HIGH functionality of all of the digital inputs throughout the program. The ESP8266 IO pins have internal pull-up resistors, so I activated them on the input pins, meaning that I wouldn't need to connect external resistors for any switches / buttons. This also means that all digital inputs would have their behaviour inverted - triggering LOW instead of HIGH - and all switches would need to connect to ground. So this involved 2 steps:
    • replace all occurrences of "pinMode(pin, INPUT)" with "pinMode(pin, INPUT_PULLUP)"
    • replace all occurrences of "digitalRead(pin) == HIGH" with "digitalRead(pin) == LOW" and vice versa
  • change all the pin numbers to reflect new pin assignments that match the ESP-12 board.
  • remove all code referencing the RTC and plugging in constant values until network time can be achieved.
  • insert this line: yield(); into the bottom of the function delayInMicroSeconds located in the Functions.ino file.
Useful tip: in cases of error, the ESP8266 typically defaults to a Serial output speed of 115200 baud. So, it is useful to change the program baud rate from Serial.begin(9600); to Serial.begin(115200); so there's no chance of missing any error messages.
At this point, the code should compile and upload comfortably to the ESP board.

The EEPROM code needs to be modified, however. I have made the modifications noted on the ESP8266 Arduino Github page, but the device refuses to save anything to EEPROM. Decidedly weird. And if it doesn't save to EEPROM the program loses a lot of its worth since you'd have to redirect the machine every time it loses power.
« Last Edit: November 03, 2015, 11:00:06 PM by alobo »