MacroDuino Project Page

Page for the MacroDuino project. The aims of this project are to make it easier to get a project up and running without writing any (hopefully) code. The vision behind it is to be able to put a couple shields on an arduino, upload a sketch and have it doing what you want without spending time writing code and debugging. You could also think of it this way: if the Arduino is a rapid prototyping device than the MacroDuino code is rapid coding. You spend 5 minutes setting up the code and configuring it and you're done.

Background

The MacroDuino code is broken up into several different pieces. The first are the interfaces. Right now there are two interfaces: serial and ethernet (official ethernet shield). The second part is the control. The control function takes the input from the interfaces and parses it into a command for the arduino to execute. The nice thing about this is that in order to add another interface all you need to do is write a small function that gets the input data and formats it so the control function can understand it.

Next there are macros. Macros can be anything and right now there are quite a few of them. All macros are stored in EEPROM so there's no need to worry about setting them up again if the power goes out. Macros basically watch something (pin, time, or temperature) and perform an output based on the input.

The last part are outputs. Examples of outputs are digital pins, pins on a PCF8574, an LCD display etc. These outputs are controlled via macros (and individually).

If you find something that doesn't work let me know. I may have made a mistake in the documentation. Just use the contact link above and I'll fix it ASAP.

More Info

I'm continually doing writeups about the macroduino code and the macroduino webapp. You can follow these tags which will show you the most recent articles.

Code

MacroDuino Code on Github

MacroDuino Webapp Code on Github

Webapp

Configuring The Code Video

Using The Webapp

Using Cosm With MacroDuino

Interfaces

Serial

The serial interface expects data in this format:

COMMAND/ARGUMENT1/ARGUMENT2

For example, lets say you wanted to turn pin 9 on. You would send 4/9/1.

Ethernet

The ethernet interface works almost the same as the serial interface. It expects a URL like this:

http://my_ip_address/COMMAND/ARGUMENT1/ARGUMENT2

So to turn pin 9 on you use a URL like this: http://192.168.1.100/4/9/1

Commands

The command list is quite long, but since they are all the same format it is hopefully easy for beginners to understand. If you have any questions or suggestions feel free to email me.

*all commands are numbers*

*updating documentation to reflect the new universal macro set function*

Command 255: Returns the Arduino's address.

 

Is a byte and values range from 0 - 255. Not really implemented in code yet, but will be useful if you have multiple arduinos on the same network (using something like an XBEE, this address would help you differentiate them).

Example: For serial just send 255, for ethernet send http://ipaddress/255

Command 1: Set Arduinos address

Syntax: 1/ARDUNOADDRESS

Example:

Serial- 1/110 -> sets address to 110

Ethernet- http://ip_address/1/110 -> sets address to 110

Command 2: Reset Macros

Command 2 resets all the macros that have been stored on the EEPROM. It erases ALL OF THEM so use only if you really want to.

Command 3: Set pinMode

Command 3 allows you to set the pinMode of any of the digital pins. This pinmode is also saved to EEPROM so when you power up the arduino again it will have the same pinmodes as you had previously set.

Example:

Serial- 3/9/0 -> sets pin 9 as a digital input

Ethernet- http://ip_address/3/9/1 -> sets pin 9 as a digital output

Command 4: sets pin status (digitalWrite, analogWrite)

Command 4 allows you to use the digitalWrite and analogWrite for any of the digital pins.

Example:

Serial- 4/9/0 -> turn digital pin 9 OFF, 4/9/1 -> turn digital pin 9 ON

Ethernet- http://ip_address/4/9/100 -> does PWM value of 100 (can use this for serial as well)

Command 5: Universal Macro Set command

*MACRO_NAME is a maximum of 5 characters long and can't include numbers

*set OUTPUT_PIN to 254 to use PCF8574 as outputs

*set PCF8574_PIN to 0-7

* if you set an output action that isn't a 0 or 1 with pcf8574 arguments it won't work

<>= -> Greater, Less Than, Equal To

Less than = 1

Greater than = 2
Equal to = 3

Watch Digital Pin Macro

Syntax:

5/MACRO_NAME/1/WATCH_PIN/WATCH_STATE/OUTPUT_PIN/OUTPUT_ACTION/PCF8574_DEVICE/PCF8574_PIN/

Example: Macro NAME, Watch pin 5 for HIGH, Turn pin 9 to PWM 100

5/NAME/1/5/1/9/100

*Note: The time on argument is a delay function so your sketch will basically stop running for that amount of time

Watch Analog Pin Macro

Syntax: 5/MACRO_NAME/2/WATCH_PIN/WATCH_STATE/<>=/OUTPUT_PIN/ACTION/PCF8574_DEVICE/PCF8574_PIN/

Example: Macro NAME, Watch analog pin 5 for 500, if less than 500 turn pin 9 ON

5/NAME/2/5/500/1/9/1/5

DS1307 Macro

Syntax:

5/MACRO_NAME/3/HOUR_START/MIN_START/HOUR_STOP/MIN_STOP/DOW/OUT_PIN/ACTION/FADE_TIME/PCF8574_DEVICE/PCF8574_PIN/

DOW refers to day of week (1 - 7). If not going to use pass 0.

Example: 5/test/3/21/50/23/59/6/9/160/3/0/0/

Turn pin 9 PWM 1. Turn on at 21:50 and off at 23:59 with a fade time of 3 minutes on/off.

DS18B20 Macro

Syntax:

5/MACRO_NAME/4/SENSOR_NUM/<>=/WATCH_STATE_WHOLE/WATCH_STATE_DECIMAL/OUTPUT_PIN/ACTION/PCF8574_DEVICE/PCF8574_PIN

Example: Macro NAME, Watch sensor 3, If less than 78 degrees F turn pin 9 ON

5/NAME/4/3/1/78/00/9/1

*You need to break the temperature up into the whole and half parts WATCH_STATE_WHOLE/WATCH_STATE_DECIMAL

ie. 78.25 = 78/25

Command 6: Control PCF8574 pin.

Syntax: 6/DEVICE#/PIN/ACTION

Example: Turn pin 0 of device 0 (all pins grounded) to ON

6/0/1

Command 7: return digitalRead for pin

Syntax:

COMMAND/PIN_NUMBER

Example: Find out digitalRead value of pin 9

7/9

Command 8: return analogRead for pin

Syntax:

COMMAND/ANALOG_PIN

Example: Find out analog value for pin 5

8/5

Command 9: Set DS1307 time

Syntax:

COMMAND/HOUR/MINUTE/SECOND/DAY/DAYOFWEEK/MONTH/YEAR

Example: Set RTC to Tuesday 12:30:45 June/14/2011 (day of week for tuesday = 2 (I think))

9/12/30/45/14/2/6/11

Command 10: Return the current time

Syntax:

10

Example: Print time

10

Command 12: Display time on LCD as 12H or 24H

Syntax:

COMMAND/12/DISPLAY_TIME_AS

Example: Display time as 12H

12/0

Command 13: Discover 1Wire devices

Syntax:

COMMAND

Example: discover all connected 1wire devices. Addresses are stored in EEPROM so if you connect new devices just run this command and you can access them much easier.

Example: discover 1wire devices

13

Command 14: 1wire devices stored in EEPROM

Syntax:

COMMAND

Example: list all devices that are stored in eeprom.

14

Command 15: Get DS18B20 temperature reading

For this command you need to run command 13 first as this command reads the address stored in eeprom.

Syntax:

COMMAND/TEMP_SENSOR_NUM

Example: return temperature reading for the first sensor discovered

15/0

Command 16: Display time on LCD

Syntax:

COMMAND/DISPLAY_TIME_ON_LCD      (1/0 = true/false)

Example: Display time on LCD

16/1

Command 17: Column & Row to display time on LCD

Syntax:

COMMAND/ROW/COLUMN

Example: display time on row 2, column 8

17/2/8

Command 18: Column & Row to display temperature reading 1

*note that any of the temperature readings can be assigned to whatever temperature sensor you want.

Syntax:

COMMAND/ROW/COLUMN

Example: Display temperature reading 1 on row 2 column 8

18/2/8

Command 19: Temperature reading 1 temperature sensor

Basically, you can say temperature reading 1 get the temperature from temperature sensor 5. Run the discover 1wire devices command which stores the addresses in eeprom. This way you can choose which temperatures you want to display on the LCD.

Syntax:

COMMAND/SENSOR_NUMBER

Example: temperature reading 1 use temperature sensor 5

19/5

Command 20: Display temperature reading 1 on the LCD

Syntax:

COMMAND/DISPLAY_TEMPERATURE_READING_1

Example: Don't display temperature reading 1 on the LCD

20/0    (to display it use 20/1)

Command 21: Column & Row to display temperature reading 2

*note that any of the temperature readings can be assigned to whatever temperature sensor you want.

Syntax:

COMMAND/ROW/COLUMN

Example: Display temperature reading 2 on row 2 column 8

21/2/8

Command 22: Temperature reading 2 temperature sensor

Basically, you can say temperature reading 2 get the temperature from temperature sensor 5. Run the discover 1wire devices command which stores the addresses in eeprom. This way you can choose which temperatures you want to display on the LCD.

Syntax:

COMMAND/SENSOR_NUMBER

Example: temperature reading 2 use temperature sensor 5

22/5

Command 23: Display temperature reading 2 on the LCD

Syntax:

COMMAND/DISPLAY_TEMPERATURE_READING_2

Example: Don't display temperature reading 2 on the LCD

23/0    (to display it use 23/1)

Command 24: Column & Row to display temperature reading 3

*note that any of the temperature readings can be assigned to whatever temperature sensor you want.

Syntax:

COMMAND/ROW/COLUMN

Example: Display temperature reading 3 on row 2 column 8

24/2/8

Command 25: Temperature reading 3 temperature sensor

Basically, you can say temperature reading 3 get the temperature from temperature sensor 5. Run the discover 1wire devices command which stores the addresses in eeprom. This way you can choose which temperatures you want to display on the LCD.

Syntax:

COMMAND/SENSOR_NUMBER

Example: temperature reading 3 use temperature sensor 5

25/5

Command 26: Display temperature reading 3 on the LCD

Syntax:

COMMAND/DISPLAY_TEMPERATURE_READING_3

Example: Don't display temperature reading 3 on the LCD

26/0    (to display it use 26/1)

Command 28: Print pH value for pin

Syntax:

COMMAND/PIN

Example: get pH for pin 2

28/2

Command 29: Column & Row to display pH on LCD

Syntax:

COMMAND/ROW/COLUMN

Example: display pH on row 2, column 6

29/2/6

Command 30: Print pH value to LCD

*note the this measurement is taken from the sketch. If you want to change which pin you're pH circuit is hooked up to change #define PH_PIN at the top of the MacroDuino sketch.Syntax:

Syntax:

COMMAND/PRINT_PH_VALUE_TO_LCD

Example: print pH reading to LCD

30/1

Command 31: List macro #

Since there are 400 bytes worth of macros you can only view settings of 1 macro at a time.

Syntax:

COMMAND/MACRO_NUMBER

Example: List Macro #0

32/0

The return data is json. First number is the macro number (used in the webapp). Second number (after comma) is whether it's enabled. Third number is macro type.

The macro type will give you a clue as to what the 4 - 10 numbers are. Simply take a look at how the macro is configure in the documentation and you can figure out what the settings are. This command is used in the web app to list out all the macros and parse what they actually do.

Command 32: Delete Macro #

Syntax:

COMMAND/MACRO_NUMBER_TO_DELETE

Example: Delete macro 0

32/0

Comand 35: Set IP Address

Syntax:

COMMAND/IP_FIRST_OCTET/IP_SECOND_OCTET/IP_THIRD_OCTET/IP_FOURTH_OCTET

Example: Set IP address to 192.168.1.102

35/192/168/1/102

Comand 36: Set Subnet Address

Syntax:

COMMAND/SUBNET_FIRST_OCTET/SUBNET_SECOND_OCTET/SUBNET_THIRD_OCTET/SUBNET_FOURTH_OCTET

Example: Set Subnet address to 255.255.255.0

36/255/255/255/0

Comand 37: Set Gateway Address

Syntax:

COMMAND/GATEWAY_FIRST_OCTET/GATEWAY_SECOND_OCTET/GATEWAY_THIRD_OCTET/GATEWAY_FOURTH_OCTET

Example: Set Gateway address to 192.168.1.1

35/192/168/1/1

Comments

Really great site, I really like the idea of setting up macros via the serial interface. I wrote a programme, in VB, to set the time on the DS1307 to the PC time. Using a VB GUI inteface I imagine some pretty complex control strategies can be setup for the Arduino, allowing easy configuration with a PC connected and continuous control when the PC is disconnected.

Submitted by Dana (not verified) on
Can you still ramp up and down with WDS1307MACROSET using type 1 and 2 as before?

Submitted by andrew on

Updated the code to do 1 hour fades with the macro. Set type to 2. Minute on and minute off should both be 0 so that means you can only do fades starting at the top of the hour.

Submitted by Nuno Borges (not verified) on
Some suggestions: - Allow for temperature to be printed in F and Celsius. - Store Max and Min values for Temp and PH, (or any other sensor) .RESET Counter .PRINT MAX MIN Temp (since last reset) 23/05/2010 03:00 min t 28,30C 23/05/2010 14:03 Max T 29,00C .Print Max Min PH 23/05/2010 20:00 min PH 6,78 23/05/2010 09:00 Max PH 7,0 I like very much your project. Quite interessed to control my LED PWM driver for Sunrise and Sunset and also to connect PH probe to control CO2 injection.

Submitted by andrew on

I was hoping nobody would catch the F and C lol. That's in my todo list.

I like the max and min value ideas. I just had an idea that you you could set any of the macros to automatically log the min and max values during the configuration stage.

Submitted by Nuno Borges (not verified) on
European people always are problematic !!! C instead of F.... Nuno Live from Portugal

Submitted by andrew on

That's right. You need a webkit based browser to be able to use the app on your computer (Chrome, Safari, etc.). It will work great on android and iphones.

Submitted by Balaji Venkatesh (not verified) on
Im interested in how you interfaced Visual Basic and Arduino!! Im working on Arduino Uno for my fresh water tank..

Submitted by squartochi on

Hi Andrew,

I have a DS18B20, why does the debug return this?

 

CRC is not valid! Device is not a DS18S20 family device. jsonp555-5555075({VALUE:{SENSOR:0,VALUE:3210}})   Hardware: Duemilanove ds1307 pin 4 and 5 ds18b20 pin 0    I have no port expander, and it will not recognise the 18b20 on the onewire pin. Thanks, Scott

Submitted by Albert (not verified) on

This is great!

I'm new at the arduino but have a Mega2560 and Ethernetshield. My goal is do home automotion. It's a Dutch project called Nodo. But before I start I want to learn something. Can you help me? I would like to have the code and webapp to turn on and off the LED with the webapp.

But how to get the code? 

Submitted by chicomoura on

Hi, i got a problem i'm trying to program a Arduino Ethernet, but i can't connect with it... i'm using Arduino 1.0, some people say the Arduino 1.0 find the IP of Ethernet board and put in Tools>Serial Port> IP xxx.xxx.xxx or something like that,to connect but that dont happen with me... i already test ping by DOS and its ok... Someone can give me a help, what i can do or what i'm doing wrong? Model: Arduino Ethernet http://arduino.cc/en/Main/ArduinoBoardEthernet OS: Windows 7 Compiler: Arduino 1.0

 

Submitted by mike_yyc (not verified) on
Hi Andrew, I'm receiving an error on verification prior to uploading the latest code: MacroDuino.cpp:66:21: error: Pachube.h: No such file or directory MacroDuino.cpp:74:27: error: cosmFunctions.h: No such file or directory MacroDuino.cpp: In function 'void loop()': MacroDuino:143: error: 'sendCosmData' was not declared in this scope Any idea what the root cause is here? I just finished adding the library to my Documents/Arduino/Libraries folder on Win7.

Submitted by andrew on
I just renamed the Pachube stuff to cosm. If you comment the #define COSMENABLED line it will compile. If you want to use the Cosm stuff I'll be bundling the library in today sometime.

Submitted by mike_yyc (not verified) on
Thanks Andrew; I'll keep an eye out for the updated library as I'll be using Pachube soon enough. Wonderful response time :)

Submitted by andrew on
You should check out the videos. Using MacroDuino to Cosm is dead simple and you can display that data on the webapp dashboard.

Submitted by mike_yyc (not verified) on
Sweet videos; very well laid out and COSM seems much easier to tackle than Pachube. Question: Is the ethernet port on the controller viable for networking or is it just a straight up port for other goodies?

Submitted by Ernst on
Great work Andrew :) thx I have the same problem met cosm missing the cosh.h file ( cosm lib. is empty ) hope to get the cosm update soon because it looks very nice in the demo video. I have an other question i'm using an ethnet shield and this shield stops working then i have to reset the complete arduino ? does anybody have this problem to ?

Submitted by andrew on
I just saw that. There was a problem when I put the new code on github. The new library is in the Libraries folder (CosmArduino) and after you put that in your libraries folder everything should compile.

Submitted by leifjoh (not verified) on
Hello. This is exactly what I've been looking for. Very simple to setup and easy to use. I am not all that experienced with coding the arduino, so this is something that I could base some projects on. I'm currently testing four DS18B20 sensors uploading values to cosm.com. Sensors A, B, C & D, all connected to PIN 2. So far this is working great. I would like to get the values in Celsius, but when I uncomment the #define CELSIUS I get this message: In file included from MacroDuino.cpp:84: supportFunctions.h:370:13: error: operator '==' has no left operand What can be the cause of this error? Cheers, lj

Submitted by leifjoh (not verified) on

Hello again Andrew.
Now the code compiles when I uncomment #define CELSIUS, but I'm still getting the values only in fahrenheit in Cosm.

One more thing. This is not a problem for me yet but something I noticed, that made me scratch my head for a few minutes.

When I use four DS18B20 sensors connected to PIN 2 and the COSM_UPDATE_INTERVAL is 10000 the values are all being sent to Cosm and everything works.
But when I change the COSM_UPTDATE_INTERVAL to 15000 or more I only get the values from sensors A & B and the data stream for sensors C & D freezes.

Cheers,
lj

Submitted by andrew on
I'll have to play around with the code so I can reproduce this and try and get it fixed.

Submitted by andrew on
As long as they're compatible with the official ethernet library I don't see why not.

Submitted by asasapd on
Hi Andrew, i dont undestand why in runDigitalMacro theresn't the command to set the pin off "digitalWrite(EEPROM.read(mem_address + n), 0);" Maybe i miss something :) Thanks

Submitted by Tim (not verified) on
Hi, I've config my code and uploaded to the arduino. with serial I've set the ip-adress, submask, and gateway. But if i type (192.168.1.100) the ip adress, he can't find the device. Can you help me?

Submitted by andrew on
In the serial monitor type 255 and then . Can you paste what it spits out here?

Submitted by andrew on
Humm, it's been awhile since I've hooked into cosm so something may have changed. I don't have time right now to fix the code, but if you find that they've changed the URL I can plug that in and push it out to the web app so it works again.

Submitted by leifjoh (not verified) on

Hi. I've been using the macroduino with cosm.com for a few months now and it is working perfectly. So far I've only been measuring temperature with the DS18B20 sensors. Now I'm trying to set up a water flow sensor as well. I've gotten the flow sensors values to the arduino, and it is working great on an individual code. But I'm no sure how I can implement this with the macroduino code. The sensor is a hall sensor sending pulses to a digital pin on the arduino.
Do you have any suggestions how I could get this working and sending the values to cosm? :)
Cheers. LJ

Submitted by andrew on
Hey LJ, It might be best if we had a skype chat about how you'd go about adding support for other sensors. Documentation for that area is lacking. Andrew

Add new comment