Skip navigation
2012

logo.jpg

Last week, Ladyada joined our Community, and several of Adafruit's wonderful Open Source Hardware products are available from Newark element14!  Several of the newly added products are ideal for Arduino projects.

 

I dig Adafruit's handy 8x8 LED matrix modules which come in GreenGreen, YellowYellow and RedRed.  Only two I/O pins are needed to hook these displays up to the Arduino via I2C (plus power and ground).  Their great tutorial makes it easy to get started:

ID1050_MED.jpg

These displays can be combined together to make awesome Halloween projects:

jackolantern.jpg

They look great animated together:

 

 

If you need more inspiration, then checkout the epic e-demon costume by Phil Burgess of Adafruit.

 

 

Adafruit's 16x2 character LCD shield kit16x2 character LCD shield kit is a great way to add both a display, pushbuttons and backlight control while saving I/O pins for the rest of your project.  It uses the I2C bus just like the 8x8 matrix displays above:

772_MED.jpg

Adafruit's tutorial gives clear instructions for assembly and using the Arduino library for the shield.  "Hunt the Wumpus" shows how the display and buttons could be used to create a simple game:

Hunt_The_Wumpus_Splash.jpg

 

Want to make a data logging project that records time-stamped sensor readings?  A Real Time Clock (RTC) can keep time even between power loss, and the DS1307 RTC breakout boardDS1307 RTC breakout board is an easy way to add one to an Arduino:

batt_t.jpg

Adafruit's tutorial shows how to assemble the board and provides example Arduino code for retrieving the date and time from the RTC.

 

 

Finally, want a low-power, high-contrast display that will make your project standout?  Then checkout this blue OLED character displayblue OLED character display:

823_MED.jpg

Adafruit's character LCD tutorial shows how to wire it up and then grab the Arduino OLED library to try out the example sketch.

 

 

Happy making!

Drew

New Release - Arduino Debugger

 

The Arduino Debugger has taken another step forward. Previously the debugger provided trace/break/step and graphical visualizations. The latest release allows the update of  variables and registers while an Arduino is running. Variables can be updated while the Arduino is running normally (in debug) or during a debug break (pause) event.

 

Read more about Modifying Variables On A Running Arduino at visualmicro.com

 

For this example we show a really pointless (and rubbish) arduino program in debug mode. The message trace has been frozen at a point that makes best reading. The entire arduino program code is shown, You can see that the values of variables are defined to be different to the current values shown in the expression watch window. The serial window shows confirmation that the changes to variable values were succesfully accepted by the Arduino. The variables with a yellow background color are read/write.

 

Visual Studio 2012 in debug mode with the Arduino plugin. Click the image to exand

http://www.visualmicro.com/pics/DebugSetVariableRunningExample2.png

Original Arduino Debugger Post

Introduction

Earlier, I saw the post about the BrewPi and I got excited.  I mean really excited.  After reading up on it, I decided that I wanted to give it a shot and build one.  However, there was at least one thing that I wanted to change.  I didn’t want to crack open the fridge and start messing with the circuits inside.  That’s when I came across a blog post describing how to hack a wireless power switch and control it with an arduino.  This sounded much simpler and safer.  Also, I added a light sensor to the netduino in order to detect whether or not the power was on.

Hacking the Remote Control

To modify the remote control, I followed the steps listed here.  Here’s the circuit to build:

IMG_0655_web_anno.jpg

Here are the connections to the remote control:

IMG_0644_web_anno.jpg

Additional details can be found in the original blog post

Writing the Code

The code is fairly straight forward.  We are going to write an event handler so that when the button on the netduino is pressed, our code gets called.  To do this, we declare the button to be an InterruptPort:

 

InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

 

Then we add an event handler to the OnInterrupt event:

 

button.OnInterrupt += new NativeEventHandler(button_OnInterrupt);

 

To start out, we are just going to toggle the state of the onboard LED:

 

private static bool isLedOn = false;

private static OutputPort led = new OutputPort(Pins.ONBOARD_LED, isLedOn);

private static OutputPort d0 = new OutputPort(Pins.GPIO_PIN_D0, false);

 

static void button_OnInterrupt(uint port, uint data, DateTime time)

{

  if (data == 0)

  {

    isLedOn = !isLedOn;

    led.Write(isLedOn);

  }

}

 

Now, if we push the button, the LED should turn on, and if we push the button again, the LED should turn off.

 

Our ultimate goal is to turn on/off the remote power supply, so inside the if statement, we will add the following code:

 

d0.Write(true);

Thread.Sleep(100);

d0.Write(false);

 

What this does is that it turns on the d0 (digital 0) output port, sleeps for 100 milliseconds (0.1 seconds), and then turns off the d0 output port.  This is equivalent to pushing the button on the remote control, holding it down for a fraction of a second and then letting it go.

Adding a Sensor to Detect When the Power Is On

If you read a couple of follow up posts to the blog that this is based on, the author ended up ditching the power switches used in this blog for different model so that they could be more certain whether or not the power was on.  Another option is to add a light sensor and detect whether or not the light on the front of the power switch is on.  This short video shows the light turning on when the switch is turned off:

 

 

So, by placing a sensor next to the light, we can determine whether or not the light sensor is on.  The circuit for the light sensor is a really easy one, and looks like this:

 

LightCircuit.png

 

All that is left is some code to read the sensor and write out the value to the screen:

 

AnalogInput a0 = new AnalogInput(Pins.GPIO_PIN_A0);

 

while (true)

{

  int val = a0.Read();

  Debug.Print(val.ToString());

  Thread.Sleep(100);

}

 

By doing this, we can then tell whether or not the light is on, which in turn lets us know whether or not the power is on.

 

Here’s a video demonstration of the project:

 

 

Conclusion

In this project, I hacked into a power switch remote controller in order to control it with a netduino, and implemented a light sensor to make sure that the command that I sent to the power switch was correctly received and executed.  Hopefully, I’ll be able to build upon this and hook it up to a fridge!

 

See Also

Netduino Tic Tac Toe

Introduction

While working on a netduino web server, I really liked the idea of doing some PHP-like preprocessing on the websites before they were returned for the client.  Basically, the netduino would make a fantastic low power web server, and if I wasn’t expecting much traffic – I was thinking something for my own personal use – then it wouldn’t have to scale to a large number of users.

 

So, I wanted to add a mini compiler to it so that I could interpret some basic commands and create a small web page on the fly.  Luckily, I decided to start small and implement tic tac toe.  The basic idea was that the user would play against the server, so it would have to be capable of accepting the user’s choice of which square that they wanted and then make a move.  The server would also have to determine who won or if the game was a tie.

Creating the Board

First off, I needed to create a game board.  Here’s what the board looks like:

Along with the HTML code that creates the board:

 

<html>

<head>

                <title>Tic Tac Toe</title>

                <style type="text/css">

                                div.row {

                                                height: 100px;

                                                width: 306px;

                                                margin-left: auto;

                                                margin-right: auto;

                                }

                                div.col {

                                                float: left;

                                                height: 100px;

                                                width: 100px;

                                                font-size: 85px;

                                                text-align: center;

                                }

 

                                div.center_row {

                                                height: 100px;

                                                width: 306px;

                                                margin-left: auto;

                                                margin-right: auto;

                                                border-top: 3px solid black;

                                                border-bottom: 3px solid black;

                                }

                                div.center_col {

                                                float: left;

                                                height: 100px;

                                                width: 100px;

                                                font-size: 85px;

                                                text-align: center;

                                                border-left: 3px solid black;

                                                border-right: 3px solid black;

                                }

 

                                div.center {

                                                margin-top: 40 px;

                                                text-align: center;

                                }

 

                                button.empty {

                                                height: 85px;

                                                width: 85px;

                                                margin-top: 7 px;

                                }

 

                                button.another {

                                                font-size: 50 px;

                                }

                </style>

</head>

<body>

                <p style="font-size: 100px; text-align: center;">

                                <span style="color: red;">Tic</span>

                                <span style="color: blue;"> Tac </span>

                                <span style="color: black;">Toe</span>

                </p>

                <div class="row" style="margin-top: -50px;">

                                <div class="col">

                                                <?sme $b00 ?>

                                </div>

                                <div class="center_col">

                                                <?sme $b01 ?>

                                </div>

                                <div class="col">

                                                <?sme $b02 ?>

                                </div>

                </div>

                <div class="center_row">

                                <div class="col">

                                                <?sme $b10 ?>

                                </div>

                                <div class="center_col">

                                                <?sme $b11 ?>

                                </div>

                                <div class="col">

                                                <?sme $b12 ?>

                                </div>

                </div>

                <div class="row">

                                <div class="col">

                                                <?sme $b20 ?>

                                </div>

                                <div class="center_col">

                                                <?sme $b21 ?>

                                </div>

                                <div class="col">

                                                <?sme $b22 ?>

                                </div>

                </div>

 

                <div class="center">

                                <?sme $another ?>

                </div>

</body>

 

So, I used the same style as my previous post, where the custom code is enclosed with <?sme … ?> tags.  Also, like last time, I just have a couple of “variables” that are going to get replaced with HTML code.  The variables specify the board position, so the upper left hand square is $b00 and the middle square is $b11.   The $another variable is a place holder to ask the user if they want to play another game.

 

So, this is not really close to a mini compiler at all.  Luckily, I started small with just variables like last time.   I was lucky because the latency on server responses was pretty slow. So slow, that I would claim that it is unusable.  If a variable substitution doesn’t work, then there is no way that interpreting the code and then executing is going to have a reasonable response time.  Therefore, I think that the complier idea is a bust, but I was still able to make a website to play tic tac toe against.

On the server side, it stores the state of the board and every time someone comes to the website they are presented with a blank board like the one above.  This is done by replacing all of the board variables ($b00, etc.), with the following HTML code:

 

<button type=button class=\"empty\" onClick=\"location.href='tictactoe.sme?id=" + _id + "&loc=" + (3*row + col + 1) + "'\" />

 

Where id is a random number assigned to every game (so that the server can track the board state) and the loc is the board position, where the top left is 1 and the top right is 3. When the user clicks the button, they are redirected to a URL that looks something like this (I chose the upper right hand corner):

 

http://localhost:1554/tictactoe.sme?id=1128789054&loc=3

 

When the server receives a URL like this, it looks up the board associated with that id and selects the square for the user specified by the loc parameter.  It then picks a move for itself and returns the board to the user.

Server Opponent AI

I implemented two algorithms for the computer.  The first one I found from this website:

 

http://ethangunderson.com/blog/minimax-algorithm-in-c/

 

It is basically an optimal tic tac toe algorithm, so it will either win or tie.  (It will never lose.)  After a couple of times playing against it, I really wasn’t having any fun, so I decided to implement another strategy for the web server.   This time it would randomly pick a square.  This also didn’t turn out to be much fun to play against, but it was a little bit better because this time I could win!

So here it is in action. The first video is one of me playing against the optimal opponent and the web server is running on my desktop PC:

 

And the second video is of me playing against the random opponent and the web server is running on the netduino:

Conclusion

As you can see from the second video, the lag between me choosing a square and the web server responding is pretty long.  Too long really.  Therefore, I abandoned my original plan of creating a mini compiler and just stuck with my variable substitution code.  If you have any questions about the implementation the code is attached or you can post a question/comment about the project to the comments section. I always like to hear feedback about my projects.

See Also

Netduino Web Server

Netduino Controlled Power Outlet

Filter Blog

By date: By tag: