Arduino

Arduboy FX

I recently picked up a neat little device called an Arduboy FX. It was a bit of an impulse buy after someone posted about getting one on Threads. It turns out it’s not actually particularly new, the community goes back quite a few years, but it’s still pretty cool none the less, and I am happy with my experience with it.

So what is it? It’s a small credit card sized handheld based on the Arduino. On a related note, it’s “credit card sized” in footprint, not so much in thickness. I wouldn’t trust putting this in a wallet at all, because I feel like my fat ass would snap it if I sat on it. The form factor is worth mentioning though. Traditionally for handhelds, I prefer the “larger options”. I had the full sized 2DS, and the XL 3DS and the large wide Retroid, and I just like, more hand real estate. Despite the Arduboy’s pretty small size, it’s still surprisingly comfortable and I don’t have any problem using it.

Also, the platform itself is open source, so one could buy components and just, build their own, if desired.

This specific version, the Arduboy FX, is different from the older original release, simply called the Arduboy. I believe the main (and possibly only) difference is that the FX includes an add on FX chip and has 200+ built in applications and games. When I ordered mine, I noticed that they sell just the FX part as an add on for the original Arduboy. They both play the same games, but the original can only play one game at a time, whatever is loaded onto it from the Arduino software. You can still load custom games to the Arduino FX.

One thing I want to mention, because it was the first question I had. What happens to the default games when you load a custom game. the answer is, they are all still there. When you upload a custom game or code from the Arduino software, the new game will load, unless you select a game from the included games list. If you choose and load another game, it will overwrite the custom game. I believe there ARE ways to overwrite the original 200 games firmware, but the standard method of upload through the Arduino IDE, does not.

As far as I can tell, most of the worthwhile available games are pre loaded on the Arduboy FX. Basically everything about this is open source in nature. I’m not going to cover any real specifics of the games here, I may do that later over on Lameazoid.com though.

The fun part here is developing games. There is a great multipart tutorial available here, though the last two parts to build Dino Smasher are not complete. The Arduboy is based on C and C++ like the Arduino is. It uses a special library to work the Arduboy functions for button presses and graphics. The tutorials are good and could be done by someone who has no programming experience, though I’ve had pretty extensive experience at this point and they were a nice refresher for my C/C++ knowledge, which I have not used in almost 20 years.

I don’t recommend the other tutorial path though, for the platform game. I’ll be blunt, its presented as beginner-ish, but it’s quite a few levels above the first set of tutorials. It introduces a lot of much more abstract coding concepts. It’s probably good information, but it’s kind of beyond a basic level and many of the comments in the community expressed as much. I was a bit worried when right out of the gate it’s starting with various types of int (integer) variables which can be used. I mean, that’s all great to know, but for the purposes of anything made here, just using int, is going to be fine.

I went through the first tutorial set myself, and built the Pong Game. This is the second time I’ve made Pong funny enough, the first being in Python. After finishing the tutorial, I went through and added a bunch of additional features. Most were things done by other commenters, but rather than pick through their code, I just made a list of ideas and added them all in. I’d recommend it for anyone looking to test their ability a bit beyond this Tutorial, especially if you have some coding ability and want to flex yourself a bit. Here is a little list of suggestions.

  • Add a pause option (easiest is when pressing A during a game)
  • Add a more complex Title screen and End Screens
  • Add a “net” line down the middle.
  • Add an ability to adjust the paddle size (this will probably also require adjusting the AI sensitivity to make the game winnable)
  • Add the ability to select how many wins are needed to win
  • Make the game a bit better by offsetting the ball starting location after scoring.
  • Make the game a bit better by starting the paddles in the middle (The AI tends to miss the first 2-3 shots right out of the gate otherwise)
  • These last couple will need to be added to the title screen.

Anyway, My finished code can be found here.

I’m pretty happy with the result. I’m looking a bit into how to embed these games into my website here, or on my Github.io page. Until then you’ll need an Arduboy to actually run the code.

I’m not sure what I want to do next yet. I may make a go at building a simple Tic-Tac-Toe game, from scratch, just to have a simple project to test my coding chops without using a Tutorial as a base. After that, I am thinking of remaking one of the first games I ever made, a simple text based RPG I had made back in High School called Dragon Quest.

Dragon Quest was vaguely based on Dragon Warrior, which at the time, I didn’t know was actually called Dragon Quest in Japan. The game itself wasn’t actually anything LIKE Dragon Warrior though, it just, was fantasy based, and had Dragons, and the name “Dragon Warrior” was taken. (and like I said, I didn’t know at the time Dragon Quest was ALSO taken, by Dragon Warrior). That game, would be well suited to remake for the Arduboy though as it too was for a simple 2 color platform, I had built it on my TI-85 Calculator. Unfortunately, I don’t have any of the code from it. A lot of people in school had gotten copies of it on their own calculators, and Iw ould get copies back after school forced my calculator to be wiped for tests, to prevent cheating. Also, my calculator is 25 years old now, so the memory has more than wiped itself. I did eventually get a TI-85 data cable, but not in time to save my RPG game code. But I still have a basic idea of how the game worked.

I may try to make the “first game”, which was just a loop of battling and healing in town, with two monsters and an end boss. Then expand it to be more like the second game which was similar, but added equipable items, more monsters, and just more complex game play. If that works out, I can try to add in the map system I had planned to use for a 3rd iteration, written in C, that I had never finished. I do have the code for that floating around.

A Pile of Used Tech

I recently had an idea occur to me that I might be able to pick up used Raspberry Pis off of eBay more affordably than buying them new. I didn’t really find a ton of savings, but I did pick up an auction for a lot of various parts for fairly cheap.

I am not sure what I’m going to do with all of this, but it seemed like a deal for around $50. I was worried that it wouldn’t all be included, but it was. Not everything is what I had hoped though. Two of the three Raspberry Pi 2s seem to be dead. I’ve tried several trouble shooting methods so far. They turn on, but don’t seem to real SD cards at all.

The arduino is a genuine Arduino, which is nice, but its a fairly older model. Not a huge issue, but it is what it is. The screens were a nice bonus. I’ve been looking into getting a screen of some sort of my Pis, possibly for a RetroPi handheld build. I have not tested the larger screen yet, it seems to work off of a funky daisy chain of an extra board and some cables. I did get the smaller screen working… ish.

It’s a nice little touch screen that fits nicely on top of the Pi. I have not had a chance to properly troubleshoot it, but the touch works kind of funky on it. For one, it seems to function more like a track pad than a straight touch. Two, the mouse cursor only wants to move along a diagonal axis across the screen.

This all kind of feels like a configuration issue however, so there is some hope. Plus I am not sure I really need a touch interface for a RetroPi handheld build.

There’s some other fun stuff that I have not had a chance to mess with yet. There were a ton of ultra sonic sensors. I’m not sure what exactly these could be useful for, but I am wondering if they would be able to do 3D imaging of an object or a space.

There’s some funky board with a digital display on it that seems to be some sort of power board. I am not sure I’m going to have a use for this at all.

Lastly, there is a Raspberry Pi camera module. I have not had a chance to test it out yet, but like the screen, this was something I’ve been wanting to try out.

Internet of Things, Internet of Stuff

I wanted to take some time to touch on my every changing collection of Internet of Things style devices.  Honestly, it’s kind of iffy what constitutes an “IOT” device, but for the most part I’m sticking with “cheap” and “non traditional computing devices”.

The chief player among these are of course…

The Raspberry Pi

I’m up to 5 Raspberry Pis, a B+, two B2s, one B3, and one Pi Zero.  I have already discuss these quite a bit so they don’t need a ton of additional discussion.  The B+ still operates my DNS/DHCP server, one B2 still runs my IRC stuff, one B2 still runs a Minecraft server.  I actually have not yet come up with a good use for the B3 and Zero yet.  I’ve started messing with Windows 10 IOT on the B3 a bit and there is a Retro Gaming GameBoy project using the Pi Zero floating around on Reddit I may have a go at.

Arduino

If Raspberry Pi is the king of IOT, then Arduino is definitely the Queen. I’ve kind of dropped out of doing Arduino projects a bit and dismantled most of the ones I had built.  Other than adding a WiFi enabled board to my set (by mistake, I thought I was ordering a Shield not a board), not much has changed on my Arduino library.

i did try to build a little digital hourglass project I found online but it’s not going super great.  Stay Tuned for More

Next Thing’s CHIP

CHIP is still one of the most annoying and impossible to search for terms online.  I’m up to three CHIPs now, I’ve received my second Kickstarter CHIP and my VGA DIP.  I’ve still been having some bad luck getting my CHIPs to do much of anything.  I tried to build an Amazon Alexa with no luck in the end after a ton of troubleshooting.  I’ve been trying to get Synergy combined and running on one to let it work with my multi monitor set up.

Now that the Kickstarter campaign is more or less finished and the CHIP is reaching a wider audience I’m hoping it starts to get more support online.

Remix Mini

Another kickstarter product, the Remix Mini is a small computer that runs Android as a desktop.  It works pretty well, I mostly used it last year while traveling for work in the Hotel Room.  I have not touched it since, for one simple, stupid reason.  The HDMI output doesn’t support any of my HDMI to DVI cables.  I can’t plug it into a regular monitor, so I just have… not used it.  I could plug it into a TV but it’s effectively a simple desktop machine and doesn’t work as well for a “lean back” experience.  Maybe if I had a wireless KB and Mouse it would work better.

It’s a shame to because I was really looking forward to this one and it runs a lot of my apps surprisingly well.

ChromeCast

I picked up a Chromecast last year on Black Friday. I used it a bit but in the end, it’s ended up in a drawer.  It’s just too much of a hassle and it caused too many problems.  First off, the hassle.  My crappy old Nexus 7 is partially to blame here but in general the lack of any built in interface is just a flat out pain.  Having to dig out my tablet to use it is a pain.

Worse yet, it was causing problems with the Wireless in the house.  I disabled guest mode which eliminated the problem (eliminating the interference) but it’s still kind of lame that it was an issue to start with.

Kindle Fire Stick

A more recent addition to the network, I added a Kindle Fire Stick.  This is effectively the same as the Chromecast, without the hassle and bull shit of needing a separate device to use it.  It’s not completely without it’s issues but it works pretty well.  The main problem I’ve had is that it loses signal, a lot.  It doesn’t work as all directly hooked to my HDMI switch and at this point it’s cabled out and laying out on the floor behind everything to get it away from any interference.

It runs Amazon videos, which I don’t really use, it runs Netflix, which is used a lot.  It also works well with the fact that I buy my MP3s primarily through Amazon.  Another nice bonus, I use Amazon Cloud to backup all of my Photos, so they are all available through the Fire Stick now to view on the TV.

SteamBox

 Another newer addition is the SteamBox.  Specifically, the cheap streaming box.  It works pretty nicely.  I haven’t had a chance to really put it through the loops yet but my first tests worked well.  I’ll probably do a more in depth write up at some point on it.

Microsoft’s Windows Remote Arduino Experience Test

I found a couple of Arduino apps in the Windows 10 App store recently, both put out by Microsoft.  There is an app that allows your Windows Phone to act as a virtual shield for an Arduino board which I ave not tried yet, but I set up and ran a quick test of the second app which lets you remotely trigger and monitor the pin inputs and outputs.

I set up a simple circuit with some LEDs on pins 2, 3, and 4, and toggle them from my desktop using the app.  There isn’t any special code needed for this, the Sketch used is the StandardFirmata sketch listed in the Arduino app under the example sketches.

There doesn’t seem to be a lot more that can be done with this app.  As far as I can tell, it’s not really set up for any sort of customizing such as naming the triggers or causing any sort of action to be taken when a trigger is activated on the Arduino (such as pressing a button to open a URL).

There is some additional information available from Microsoft about setting up Visual Studio to build Arduino projects but I have not tested it yet, I actually have run into an error in Visual Studio when trying to load the projects.

Pushing Arduino Data to MySQL via PHP Part 2: The Server

tempdataIn the last post, I talked about how to send data from the Arduino to the MySQL server.

Today, I’ll cover how I’m receiving and displaying that data on the server side.  I’ll put the code for the webpages into this post but I’ll put everything together in a nice little package at the end of everything.  I mentioned last post that the end trick was to let the server worry about processing the data instead of the Arduino.  I’m running this on my NAS but it could be run on any standard web server with PHP and SQL.

For the purposes of this code, I’ve placed the files in a directory called “temps” on the root of the web server.  If you want to put them elsewhere, such as “temperaturelog” or “home/temps” or wherever, you’d need to alter the code of the Arduino in the previous points to replace the temps directory with the directory you plan to use.  I’m going to assume that the reader has a basic LAMP (Linux, Apache, MySQL, PHP) stack style server and knows the basics of how to create databases and run things on it.  If not you can Google the basic set up, though I may do a quick write up and reference it here eventually.

You’ll need to create a database called “housetemps” and import the linked structure file into it.  (If you know what you’re doing in PHP you can rename housetemps)   This will create a table int he database called “temperature” with the following columns: id, event, sensor, celsius, humidity, datestamp.  This will give you the basic structure needed to run the php code on the server.  A quick rundown of what these values are used for…

  • id – A standard auto incriminating id value for SQL
  • event – Time and date of when the event happened
  • sensor – A text based identifier for each probe.  This example uses one probe but could be altered for more.
  • celsius – The temperature reading, it doesn’t actually have to be Celsius, that’s just the default of the probe.
  • humidity – Humidity reading in percent humidity
  • datestamp – A date only time stamp, used for sorting the data when you review it later.

Now that you have the core database structure set up, the server needs to know the credentials for connecting to the database.  Since this is used by several files, it’s best to put the info in it’s own file and use an include statement int he PHP to add it.

In the “temps” directory create a file dbconnect.php and add int he following code, changing the values listed for the values used when setting up the database…

<?php
$MyUsername = “USERNAME”;  // enter your username for mysql
$MyPassword = “PASSWORD”;  // enter your password for mysql
$MyHostname = “localhost”;      // this is usually “localhost” unless your database resides on a different server

$dbh = mysql_pconnect($MyHostname , $MyUsername, $MyPassword);
$selected = mysql_select_db(“housetemps”,$dbh);
?>

Next you’ll need a way to get data into the table.  This is done using add_data.php, which is called by the Arduino in the code shown previously.

Make a file in the “temps” directory called add_data.php, and add the following code.

<?php
// Connect to MySQL
include(‘dbconnect.php’);

{
$dateget = date(“Y-m-d”);
// Prepare the SQL statement
$SQL = “INSERT INTO housetemps.temperature (sensor ,celsius, humidity, datestamp) VALUES (‘”.$_GET[“serial”].”‘, ‘”.$_GET[“temperature”].”‘, ‘”.$_GET[“humid”].”‘, ‘$dateget’)”;

// Execute SQL statement
mysql_query($SQL);
}

// Go to the review_data.php (optional)
header(“Location: review_data.php”);
?>

The code is pretty straight forward. The first section includes our previously created log on credentials.  The last section forwards the page on to review the data.  The meat is in the middle with the SQL statement.  The line $dateget = date(“Y-m-d”); creates a Year-Month-Day date for sorting later.  The next line creates the SQL query using variables passed via the url, the third part executes this query adding the data to the database.

The final piece of this whole thing is the review_data.php file.  This file displays the results in a nice looking table.

<?php
// Start MySQL Connection
include(‘dbconnect.php’);
?>

<html>
<head>
<title>Arduino Temperature Log</title>
<style type=”text/css”>
.table_titles, .table_cells_odd, .table_cells_even {
padding-right: 20px;
padding-left: 20px;
color: #000;
}
.table_titles {
color: #FFF;
background-color: #666;
}
.table_cells_odd {
background-color: #CCC;
}
.table_cells_even {
background-color: #FAFAFA;
}
table {
border: 2px solid #333;
}
body { font-family: “Trebuchet MS”, Arial; }
</style>
</head>

<body>
<h1>Arduino Temperature Log</h1>

<p>Select Date:
<?php

$sql = “SELECT DISTINCT datestamp FROM temperature”;
$result = mysql_query($sql);

echo “<select name=’datestamp’ onchange=’location = this.options[this.selectedIndex].value;'”;
while ($row = mysql_fetch_array($result)) {
$current = $row[‘datestamp’];
echo “<option value=’review_data.php?dateselect=$current’>$current</option>”;
}
echo “</select>”;
?>

<table border=”0″ cellspacing=”0″ cellpadding=”4″>
<tr>
<!–    <td class=”table_titles”>ID</td> –>
<td class=”table_titles”>Date and Time</td>
<td class=”table_titles”>Sensor Serial</td>
<td class=”table_titles”>Temperature in Celsius</td>
<td class=”table_titles”>Percent Humidity</td>
</tr>
<?php
// Retrieve all records and display them
$SQL = “SELECT * FROM temperature WHERE datestamp LIKE ‘”.$_GET[“dateselect”].”%’ ORDER BY id ASC”;

//Execute the SQL
$result = mysql_query($SQL);

// Used for row color toggle
$oddrow = true;

// process every record
while( $row = mysql_fetch_array($result) )
{
if ($oddrow)
{
$css_class=’ class=”table_cells_odd”‘;
}
else
{
$css_class=’ class=”table_cells_even”‘;
}

$oddrow = !$oddrow;

echo ‘<tr>’;
//       echo ‘   <td’.$css_class.’>’.$row[“id”].'</td>’;
echo ‘   <td’.$css_class.’>’.$row[“event”].'</td>’;
echo ‘   <td’.$css_class.’>’.$row[“sensor”].'</td>’;
echo ‘   <td’.$css_class.’>’.$row[“celsius”].'</td>’;
echo ‘   <td’.$css_class.’>’.$row[“humidity”].'</td>’;
echo ‘</tr>’;
}
?>
</table>
</body>
</html>

The core of this file was lifted from the previously mentioned guide on Tweaking4All.  The problem I had with their results was that it simply displayed an endless list.  I am polling every 15 minutes, so this list tends to grow unwieldy very quickly.  This is where the datestamp marker comes into play.  I added this little chunk of code at the top of the table.

<?php

$sql = “SELECT DISTINCT datestamp FROM temperature”;
$result = mysql_query($sql);

echo “<select name=’datestamp’ onchange=’location = this.options[this.selectedIndex].value;'”;
while ($row = mysql_fetch_array($result)) {
$current = $row[‘datestamp’];
echo “<option value=’review_data.php?dateselect=$current’>$current</option>”;
}
echo “</select>”;
?>

This creates a menu based on unique values of datestamp.  Selecting a value forwards you to review_data.php with a date attached, then review_data.php only shows data that matches that datestamp.  This allows a single day to be viewed easily.  In the future I may add a bit more to this menu, eventually, the list of dates will also become unwieldy in length.  I also plan to run numerous sensors at once with different names so I’ll likely also add a second menu so the list can be sorted down by sensor name.

I’m also looking to add a bit more functionality to the code in the form of a graph, so it will be easier to see trend lines in the data.  The data I have now is from my office, in a well insulated basement room, so the trend lines are rather boring, but when there are several sensors in different rooms in the main area of the house, or even outside, this data becomes more interesting and useful.  I’ll go into this at a later day though…