I assumed it would be very simple to turn on an LED with my hannah rev3 board based on the value of a variable, but I have spent more than a few days tinkering with very complex code for such a simple action.
I made my first mile stone with being able to access the pin at all via the IO expander using a stripped down version of https://github.com/electricimp/examples/blob/master/hannah/hannah_complete.nut . I took out everything, but the ExpGPIO class stuff and was able to setup the pin with this code:
led1 = ExpGPIO(ioexp, 11).configure(DIGITAL_OUT);
I’m able to illuminate the LED, as the default state when I setup pin11 seems to be on. I now have no idea how to simply write something that will turn the LED on/off given the value of a variable. My end game is to just turn on/off the LED if the temperature reaches X, but from the trouble I am having you would think I’m trying to build a nuclear reactor.
I have some experience the Arduino, Parallax Basic Stamp 1/2 and their Propeller microcontroller, but never have had anywhere near this many complications since I picked up this Hannah board. Help! (pretty please)
Did the original example code with the RGB led work?
Generally, the arduino’s etc don’t have LEDs attached to a GPIO expander which has a 100 page data sheet… the hannah is not the simplest board to get started on, but does have the kitchen sink on board.
Your line appears to be assigning led1 to the result of that call, whereas I think you’re trying to make led1 be an object to control that pin. Possibly, and I don’t have one here to try, you should be doing something more like:
local led1 = ExpGPIO(ioexp, 11);
…then you can turn the LED on and off with calls like this:
led1.write(1); // set line high
led1.write(0); // set line low
Thank you for the response Hugo.
The fact that the hannah has the kitchen sink is exactly what brought me to it. It seemed like an very cost effective, clean and simple way to complete my project. After seeing how I was able to get the on board RGB LED working and even log temperature readings to a graphing service within the first hour of owning the board I was excited. With that said I was a bit stunned when I hit such a brick was trying to do something I figured would be the easiest part of the whole project( switching high and low) thanks to this lovely 100 page datasheet GPIO expander
I tried incorporating what you said into this nightmare of code I have mangled together without any luck. I would constantly get an error about an index being not found which I completely blame on my lack of higher level programming skills.
If it would not be too much trouble could you please give me a working example of the code? If I could only see a working example in action I’m sure it would set me on my way. The biggest problem I have found in searching everywhere is everyone has example code for doing everything complex with the board, but not this simple task I’m attempting. I think it would be a great help to the next person like me that assumes it is an easy take to blink an LED on a spare pin(or trigger a relay, or fire a rocket ship, ect)
@hugo, his code is correct. ExpGPIO.configure() returns “this”
@CallOneTech, the example code provided (here) does have a couple of examples of how to drive a DIGITAL_OUT port and hugo’s comments are correct, you just write() it to 0 or 1. But you want to start with the full class structure in place and then remove stuff piece by piece. The ExpGPIO class requires the SX1509 class which it sounds like you removed.
A friend of mine helped me sort it out. Thanks for the input