Messages - alobo

You'll manage as long as you have minimal programming chops, and I'm sure it'll come back to you quickly! Blynk is insanely easy to use considering just how much you can do with it. Interpreting my heliostat code is where it might get hairy though ... I was looking through it myself and almost couldn't remember what I'd done!

Tips:- be sure to select the correct COM port in the Arduino IDE, and set the programming speed to maximum (921000 baud)- you'll need to enter an additional source into the Arduino 'boards manager' and install the under-the-hood components that allow you to program the ESP8266 directly.- Blynk uses hard-coded 'auth token' strings to make sure it communicates with the correct device over the Internet. Keep track of yours, they are generated each time you open a new project in your Blynk phone app.

Start off with the easy Arduino example of 'blink an LED', and then you can move on pretty much immediately to 'blink an LED with Blynk' from the phone app. It's insanely simple - hell, you could even skip the basic Arduino examples entirely and start directly in Blynk using their example code. In the example below, simply insert your Wifi name/password, and the auth token provided from the Blynk phone app, and upload as-is to the NodeMCU, then plug in a LED to any of the GPIO pins.Then open your phone app, pull up a 'button' module in the project, assign it to the pin you have the LED connected to ... and press play! You're done - the LED should light up pretty much immediately as you touch the button. Wireless control in under 10 minutes and 10 lines of code! (ignoring the comments and spaces, obviously). They've seriously done some amazing magic behind the scenes of Blynk. (Hell, I should be getting paid for how much I tell people about it!)

It's great feeling to set up the ESP-12 board from scratch (all you need is 3.3V regulator, capacitor, 3 resistors, 2 switches, and a header for hooking up your FTDI programmer) as compared to building an Arduino board from scratch! You can program it many times faster than the Arduino, too (which is important considering how much program memory it has). I have my IDE set to 921600 baud programming speed, whereas the typical max Arduino upload speed is 115200. And Wi-Fi programming, when it doesn't fizzle, is even faster!

But to speed things up, I will recommend you find a NodeMCU breakout board, these usually come with an ESP-12 already soldered on, with built-in USB/FTDI and regulator. In other words, with a NodeMCU you buy it, plug it in and start programming immediately!Saves a lot of effort for a minor increase in cost (and you won't have to deal with the 2mm header spacing of the raw ESP-12 module).However, there can sometimes be minor confusion regarding the 'NodeMCU' pinout vs the 'ESP12' pinout so always have a reference handy like this one.

The NodeMCU was designed as a Lua-based device, but it functions perfectly well in the Arduino IDE! Hell, there's even a version of Python that'll fit on the ESP-12. ... But I digress.

Get yourself a NodeMCU and download the Blynk libraries into Arduino, and I can almost guarantee you that could have your phone talking to the ESP-12 within, like, half an hour (depending on your coding skill). :-)

It's been quite awhile since I've been on this forum! I got busy doing other things, but I did end up working a bit more on my heliostat coding afterward. The idea was to have a single ESP8266 controller for every machine, avoiding the need for long wire runs and messing with I/O expanders. I used A4988 stepper motor controllers but I'm sure almost anything could be used.

It ended up that I got my heliostat to: - connect to WiFi to get network time,- assign the target using the Blynk app joystick on my phone, and - save target coordinates to EEPROM.(Additionally there is a provision to be able to wirelessly reprogram the board, as long as the total program size is half the size of the internal memory. The ESP-12 modules usually have 4MB of memory, so as long as your program is under 2MB it can be reprogrammed over WiFi!)

I'm uploading my code here pretty much as it was when I last looked at it (over a year ago, so I'm not entirely sure what it looks like ...), and I'd made quite a few modifications without commenting but I hope it's readable. It should compile and run directly on the ESP12 board. Give it a shot and see (modify necessary variables like WiFi name/password, I/O pins etc)

And get familiar with Blynk because it'll really help to add functionality without needing more hardware connections. (Another option is RoboRemo, but I've never used it. Heard good things about it, so keep it in mind if Blynk doesn't work for you.)

So, I've had a hectic time working on this.The Sun Tracker compiles and runs on the ESP-12 board, but I was unable to get the EEPROM to save target values. Bummer. I was also unable to get network (NTP) time to work for some reason, although I followed the guide multiple times. Perhaps it could be my WiFi network or my ESP chip, no idea. Others seem to have NTP time working. Perhaps you guys will have better luck. At the moment the time, and the target angle, is manually set in the variables in code at upload/compile time.There are somewhat significant alterations to the code since I deleted out any code I wasn't using (commented out code actually distracts me, I don't understand why) but the structure of the program is still mostly the same. I've modified it to include the Arduino "Time" library so that once the date/time is set, the program itself keeps time (with low accuracy) as long as it has power. This will be handy if someone gets network time working, since you'd only need to sync-up the clock once a day or so.

Good luck, y'all! Sorry for my delay in uploading my code. Busy days.Particularly considering that the ESP8266 only has one ADC pin (and which is limited to 1V), I will slowly be working on adding Blynk integration as I have time ... don't depend on me for this, work on it yourselves! I got the basic Blynk programs working pretty fast when I tinkered with it, so I'm pretty sure it should be easy to add to the Sun Tracker program. Which means you'd be able to control and monitor the heliostat from your phone! Let us know what you guys come up with.

While working with the ESP8266 (which I am really really hooked on right now, in case you can't tell), a couple things came up that I think you will find useful as you upgrade the program.

Blynk.This thing is effing amazing. I got the ESP8266 and my Android phone talking blinky lights to each other over WiFi pretty goddamn fast. In the case of Arduino (or most other boards they support) you'd need a Wifi or Ethernet module, or have to leave it plugged in to the computer via Serial, to get this working. This will be literally the easiest way to add wireless control and feedback to your heliostat program.

The Arduino Time library.Assuming you experiment with connecting the program to a network and regularly fetching time from the network (NTP), the Arduino Time library can be used like a clock with or without an RTC. Worth looking into.

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. 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.

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.

GND -> SW1 -> RESET GPIO0 <- SW2 <- GNDIf 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 --> <-- TXRX <-- --> RX

This is correct:TX --> --> RXRX <-- <-- 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)"

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.

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.

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.4989Longitude: 73.8278Timezone: +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 2015UseNorthAsZero = TRUE

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?

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.

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.

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!

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:

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).

So we finally had a few days of somewhat reliable sun. It seems the reflection drifting was because of a combination of1) incorrect north-south alignment, and 2) the altitude motor missing steps.

If the sun comes out some more I'll try it with a fresh motor and double-checked wiring.

None of the nearby buildings are in line with any cardinal directions. I used a nearby landmark that looked to be in the right place on Google Maps but it seems it was nearly 5 degrees off. Using the direction-sensor on my smartphone only gives me accuracy to within one degree. That was the issue I faced, anyway, I'm sure others have their own workarounds/solutions. I finally used what I should have done at first, and measured the shortest shadow of the day on a pole, and lined up with that. (luckily the sun was out long enough to measure the shadow).

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.