Tutorial: ESP8266 + PHP and MySQL Database

I hear you guys

I see it in the view counts, comments, and emails asking for information about my ESP8266 and MySQL project I made two years ago. People are having trouble with their ESP8266 and MySQL Database projects. The reasons why I haven’t posted about it since then is because I haven’t been doing much with the ESP8266, and the project is so old that the way it’s programed is out-of-date. Development for the ESP8266 has evolved so much and made it easier. You no longer have to deal with AT commands with all of the libraries and tutorials for the Arduino IDE.

I’m going to do a quick tutorial to explain how I’ve been doing my ESP8266 with MySQL project. It’s not going to have much code but more explaining so you get what’s happening.

Before we start, some links for you

The ESP8266 blog post that everyone is showing up to see: https://mwhprojects.wordpress.com/2015/01/18/esp8266-with-a-mysql-database/

The Github repo for this, though sort of irrelevant at this point because it’s outdated: https://github.com/mwhprojects/Arduino-ESP8266

The recent NodeMCU project that showed me what’s new with the ESP8266: https://mwhprojects.wordpress.com/category/projects-2/nodemcu/garage-monitor/

The Github repo for that: https://github.com/mwhprojects/NodeMCU-MySQL

GETing values and INSERTing them

Here’s what happens in the code uploaded onto the ESP8266/NodeMCU (see Github):

  1. The ESP8266 connects to the webhost.
  2. The switch values are read.
  3. These switch values are then inserted into a URL which the ESP8266 tries to load.
  4. Repeat.

I think that step three is what people are most interested in, so let me explain that a little further. PHP has the GET method, which basically reads variables that are in the URL itself. For instance, if we have a URL like: thisisanexample.com/example.php?a=1&b=2, we could use PHP to get the values of a and b. In PHP, we’d write $somevariable = $_GET[‘a’]; and again for b. We can then use PHP to connect up to a MySQL database and insert $somevariable and whatever else you’d like into the table.

In the PHP code (see Github), the file begins with code that checks for variables in the URL as explained above. If there is, it uses the GET method to get the variables and then inserts them into the MySQL database table.

Just a heads up, the deep sleep in the NodeMCU hasn’t been working for me, as I explained with my NodeMCU project posts. Keep that in mind if you plan on adopting the code. Heck, let me know what happens with your project as it could just be something with my hardware.

So now what?

Like good old XDA… YOU TELL ME.

I’m not an expert with the ESP8266 but I’d like to help if I can. Please let me know if there’s any clarifications I should make to this post or any more specifics on what problems you’re having with a similar project.

Thanks a lot for reading and good luck with your projects!

Creating a VB Interface for Arduino Tutorial Website Update!

4When I put up the “Interfacing Arduino with Visual Basic Tutorial” website, there was a lot of pressure from people to put up information on this topic so I didn’t put a lot of effort into the website itself. After some thought, I decided to give the website a makeover that would make it both nicer looking and easier to learn from. You can check it out at mwhprojects.com/arduinovb. Let’s take a look at what’s new.

New Name. New Colors. New Layout.

2A lot of small changes have added up to a great redesign. The tutorial name has changed to “Creating a VB Interface for Arduino”. The new website feels a lot warmer with a blue and white color scheme, with a little gray too. I’m using Google Code Prettify to display the snippets of code on the website, instead of the screenshots of the IDE from before. The tutorial is now split up into pages so that there are less large walls of overwhelming text.

The Menu

1The menu gracefully slides out to display an index of all of the pages on the website. As you’ll see, it’s a lot easier to find certain concepts used in the program. The idea is that, if you’re not willing to go through the entire tutorial, you can easily find a certain concept that you’re looking for to implement in your project.

Quizzes

3I’m really excited to add a couple special features to the website. Some of the tutorial pages have quizzes at the end of them that ask questions that can be answered from what was talked about in the code descriptions. I hope you have fun with it.

Options/Bookmark

The other special feature is Bookmark. Basically, if you plan on going through the entire tutorial but can’t do it in one sitting, with the Bookmark feature enabled, all you have to do is bookmark the homepage of the website instead of bookmarking the page you’re on. When you revisit the homepage next time, you’ll get a little notification letting you know where you left off.

I was thinking of other options to add to the website, but I think this one feature is enough for a site like this.

Feedback

Please let me know what you think! Leave a comment or send me a message!

Thanks for visiting!

“How do you program the light show?”

Untitled-1

Programming the Light Shows really isn’t that complicated, just time consuming. It seems to be a mystery for a lot of people and I still don’t really understand why. Not a lot of people seem impressed by my crude technique (people always seem to expect some kind of audio processing). In this post, I’ll share some of the things involved in programming the light shows and you’ll finally see how simple it is (again, it’s just time consuming).

The Functions: The show’s programs are made up of delays and for-loops. To use the hardware, the program uses basic digital and analog write functions, as well as the servo library.

The Process: The process is simply replaying the song over and over again and adding more code to it on each run. I work on the song in verses that I mark off in the code using either a line of ////////////// or the first line of lyrics of the next verse, commented out of course. Doing it in verses gives me points where I can decide to take a break… but really, it helps me keep track of where certain pieces of code is so I can go back to it and tweak it. Sometimes I will put a really simple pattern just to figure out the timing and then go back to it later and add more effects to that section.

Cuing It Up: I use VLC to play the song when I’m programming. In the earlier shows, I used to try and cue the song manually by watching the blinking TX lights on the Arduino as the program uploaded and then started the song once it was complete. It was kind of a guessing game that I’d figure out well enough to get things done. Eventually I realized I could just have an LED counting down like this:

// Count down (4, 3, 2, 1)
for(a=4; a>=1; a–){
digitalWrite(22, HIGH);
delay(500);
digitalWrite(22, LOW);
delay(500);
}

Time: It takes about a week to program 1 minute of show. I try my best to create fresh patterns so it gets incrementally more difficult as each new show is released. It’s also gotten harder as I’ve added more components to the stage in the later versions of the light show. This is why the shows have gotten shorter over time.

CAN I HAVE THE CODE?!!?: Yes! For the first time in a long time, I’m releasing code for some of the shows, specifically the most recent three. You can get the files here: http://www.mwhprojects.com/lightshow/code

I hope this has answered your questions about programming the Light Show. If you have any more questions, send me a message or leave a comment. Now go out and blind yourself with LEDs like I have!

Interfacing Arduino with Visual Basic

I wrote a tutorial on how to interface a Visual Basic program with Arduino. It includes downloads you can open in Visual Studio and the Arduino IDE. The executable is also available if you just want to play with the example program. The example program lets you send a pin number and delay value so that an LED on the selected pin will blink with a delay that is determined by the value you send it. It also receives a success/error flag from the Arduino.

http://mwhprojects.com/arduinovb

Check out the two Arduino project videos I posted that uses serial communication with a Visual Basic program:

EERef Version 2.1 now available!

I think I’m rushing updates too much so I think I’m going to take a break from EERef…

Anyways, I’ve added two new tabs: Arduino and Pinouts. They’re both reference material that I think is handy to have for quick offline access. I tried to make it so that you get the information you most likely need without having to scroll through pages of a datasheet.

The other “new” thing is that there will be an update notification when the program starts if there is an update available. It’s a little more aggressive now because I feel it’s more important to get updates out with the new pinout material. (Yes, I know people don’t care much about this program to even think it has something like update notifications, but let me play a little.)

Get it now!

 

EERef Version 2.0 now available!

compareI am happy to announce a major update release of my Electronics Engineering Reference Windows program! The past few minor updates have been focused on the design but I felt like I was going in the wrong direction. Version 2 is a shift to a completely new design and layout. It’s a lot more polished this time around.

new1Each section now has a dedicated window with everything, including the tutorials. Pretty much everything is contained in the main program window so there’s no reason to open a bunch of other smaller windows. Removing those windows actually shaved off a third of the program’s file size.

The new design allows for the program window to be resized and maximized. There are just a couple sections that will stretch with it, but the ones that don’t really don’t need to.
new2I was going for that “flat” UI that’s trending these days. There’s a lot of Segoe UI font in there so hopefully you have it installed on your PC.

Besides the new design, a new feature is the Essential Formulas section which is just a quick reference to basic formulas. I hope to continue building on it to make it larger and to include calculators. I also fixed a bug in the number systems calculator that told you there was an overflow error if the result was 1.

Download it now!

Introducing Glow With Arduino!

logo

Glow With Arduino is an electronics/Arduino beginner’s guide I made that is focused on LED and light-based projects. It’s a website full of information, ranging from basic electricity theory to programming concepts. It also covers hardware materials I have explored in the past. I’ve tried to create a resource that lays out everything to help you decide methods of approaching your next project.

I am still exploring the idea of selling a kit to go along with some hands-on projects, but it’s just an idea at this point…

Check it out here: http://glowwitharduino.tk