MacroDuino (configurable code)

Hi All,

I just wanted to share some code that I've been working on for the last few months which is called MacroDuino (practicalmaker.com - This website is for sale! - practicalmaker Resources and Information.).

The basic idea was to create some code that would let you enable or disable some variables which would enable/disable different parts of the code, upload it to the arduino and configure a variety of different things over the serial monitor or ethernet.

I tried to break everything down into different groups. The first would be interfaces. Right now there are two (serial and ethernet). Basically you send a command to the arduino and this parses it and passes it to the control function. It's rather easy to add a new interface too, just include whatever libraries are needed and make sure you parse everything out except for the command. Than you just pass the command string to the control function.

Now comes the interesting part. There are to many commands to list, but I'll go over some of the neat ones.

  • control digital pins (and set pinmode)
  • read analog pins
  • read ds18b20 temp sensors
  • read ds1307 RTC (and set)
  • LCD output (my own board, but can easily be ported to liquidcrystal) with configurable display options
  • setup macros (analog/digital/temperature/time input) with digital pin/port expander output
  • log analog/digital/temp readings to pachube
  • webapp (practicalmaker.com - This website is for sale! - practicalmaker Resources and Information.)... need a webkit browser to use correctly as it depends on sqlite to store settings (may change to localStorage)

The neat thing about the webapp is that it's hosted on my website so there's no need to host it locally. It uses jsonp to get around the same-origin policy with web browsers. jsonp was actually pretty easy to implement. All that was needed was to parse out the function name that jquery sent and print it back once the control function was finished.

There are still quite a few space improvements to be made to the code (I got a little lazy towards the end), but right now with everything + debug enabled its less than the space of the atmega 328. Disabling functions (ie. pachube) saves space and is done by changing variables in the main code. That way you can easily add your own stuff and still have everything fit onto a standard Arduino.

Enjoy!

Is it possible to read some script from SDcard ? (optionally creating a sketch megabytes in size ... )

I don't think so, but you never know. I seem to recall doing some research awhile ago about that and found it wasn't possible.

There's absolutely no reason why it wouldn't work from an sd card. A text file could be created holding the commands that you would otherwise send over serial, and the arduino reads those and executes them according to your code.

I may be a little confused about what was asked.

You could write an SD card interface which would read commands from an SD card (thanks for bringing that up, I have ideas for that already).

You can't read a program from the SD card and run it within the Arduino.

Reading commands from SD card iso reading them from serial was what I meant.

if possible the commands should be able to perform jumps : go 5 commands back and if and while constructs.

Well, you could add the jumps part into the interface code. Basically you'd have a check when reading the current line to see if the command = 100. If it equals 100 than go back x lines.

// need global current_line_num variable
// this code won't work because i haven't used the sd card library in awhile
// mostly this would just be how the code should work

char current_line_char = read_sd_card_line(current_line_num);

char *command = strtok(current_line_char, '/');

//atoi... mostly because I forgot the syntax

if(command == 100) {
char *go_back_num = strtok(null, '/');
//atoi go_back_num
current_line -= go_back_num;
// break out of this iteration of the loop so it repeats at the new current_line start
} else {
pass to command function
}

As for if and while constructs that would be quite a bit harder because you add if and while, 2 arguments and all the operators for the arguments. I don't use strings to keep down the space and because they chew up lots of ram. It could be done, but it would take quite a bit of time to do so.

I really like that idea of reading commands from an sd card though. I'll try and get it into the code soon and we can work from there.