Forums > MaxMSP

RFID SWITCH ON LED & Dimmer control? Please Help.

March 1, 2012 | 2:12 pm

I am making a prototype using a LED to represent a real light in the home but I can’t get all my code to work together. If somebody could help me my Honours project will be complete. I want to scan a tag, tag switches on LED, MAX slider controls brightness of led. I have them all working individually but not together.

1.First I will show you the Arduino code for the RFID Reader.
2.Then Max patch for RFID Tag Reader

3.The Arduino code to switch on LED
4.The Max patch to switch on LED

5.The Arduino Code for the Led dimmer
6.The Max patch for the dimmer.

—————————
1.RFID code for Arduino: (http://hcgilje.wordpress.com/resources/rfid_id12_tagreader/)
—————————
/* RFID ID12
*/
char val = 0; // variable to store the data from the serial port
void setup() {
Serial.begin(9600); // connect to the serial port
}
void loop () {
// read the serial port
if(Serial.available() > 0) {
val = Serial.read();
Serial.write(val);
}
}

——————————
2.MAX Patch RFID Tag Reader:
——————————

copy and paste into maxmsp. You might want to clear the menu before adding your own tags:

#P window setfont "Sans Serif" 18.;
#P number 549 297 35 18 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 206 361 121 196617 filter out the 10 data bits;
#P newex 457 289 49 196617 delay 10;
#P newex 144 417 80 196617 prepend symbol;
#P message 550 178 33 196617 clear;
#P newex 508 432 69 196617 route symbol;
#P newex 508 459 78 196617 prepend append;
#P newex 508 409 41 196617 v temp;
#P newex 457 343 32 196617 sel 0;
#P newex 457 320 27 196617 0;
#P newex 525 261 21 196617 t 1;
#P newex 508 198 40 196617 t s b 0;
#P user ubumenu 550 224 100 196617 0 1 1 0;
#X add 0D003B363E;
#X add 0E002A0E4D;
#X add 0E002A393C;
#X add 0E002A0148;
#X add 0E002A047E;
#X add 0E002A0A2E;
#X prefix_set 0 0 0;
#P newex 144 391 40 196617 itoa;
#P newex 144 360 57 196617 zl slice 10;
#P newex 103 319 51 196617 zl slice 1;
#P newex 103 293 54 196617 thresh 40;
#P toggle 103 187 15 0;
#P number 145 186 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 103 210 52 196617 metro 20;
#P button 85 215 15 0;
#P newex 103 254 98 196617 serial b 9600 8 1 0;
#P comment 158 321 100 196617 filter out start bit;
#P window linecount 2;
#P comment 520 113 156 196617 checks if tag is already in list , if not adds it. if yes shows the id;
#P window linecount 1;
#P comment 281 65 80 196617 RFID tag reader;
#P comment 587 177 100 196617 clear taglist;
#P window linecount 2;
#P comment 173 212 100 196617 how often the serial port is checked;
#P connect 9 0 7 0;
#P fasten 6 0 5 0 90 240 108 240;
#P connect 7 0 5 0;
#P connect 5 0 10 0;
#P connect 10 0 11 0;
#P connect 11 1 12 0;
#P connect 12 0 13 0;
#P connect 13 0 23 0;
#P connect 8 0 7 1;
#P connect 15 1 24 0;
#P connect 24 0 17 0;
#P connect 17 0 18 0;
#P connect 15 2 17 1;
#P connect 16 0 17 1;
#P connect 23 0 15 0;
#P connect 15 0 19 0;
#P connect 18 0 19 0;
#P connect 19 0 21 0;
#P connect 21 0 20 0;
#P connect 14 0 16 0;
#P connect 14 0 26 0;
#P connect 15 0 14 0;
#P connect 22 0 14 0;
#P connect 20 0 14 0;
#P window clipboard copycount 27;

———————————–
3.Arduino Code to switch on LED:
(http://www.cycling74.com/forums/topic.php?id=34141)
———————————–
int maxData = 0;
void setup()
{
Serial.begin(9600);
pinMode((9), OUTPUT);
}

void loop()
{
while(Serial.available() > 0) {
maxData = Serial.read();
}

if(maxData == 1)digitalWrite(9, HIGH); // turn led on

}

———————————-
4.The Max Patch for turn on LED:
———————————-

– Pasted Max Patch, click to expand. –

————————————–
5.The Arduino Code for the Led dimmer (http://arduino.cc/en/Tutorial/Dimmer)
————————————–

const int ledPin = 9; // the pin that the LED is attached to

void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}

void loop() {
byte brightness;

// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
// set the brightness of the LED:
analogWrite(ledPin, brightness);
}
}

—————————————-
6.The Max patch for the dimmer.
—————————————-

– Pasted Max Patch, click to expand. –

March 1, 2012 | 3:05 pm

No time to check all those codes, but I have one remark: you seem to get both the rfid datas and Max datas from the serial port. I think it is possible (although I can’t check now) to get serial datas over the IO pins 0 & 1 AND over the USB port, but then you need a way to identify which device sent the message you received.

Or you need to use other IO pins as a serial port, which is a standard feature with the arduino 1.0 IDE (see SoftwareSerial in the examples).

p


March 1, 2012 | 3:54 pm

This Is how my arduino and led are set up. The LED closest to the reader just flashes when a tag is received and the red one is the one I want to light up. I drew this real quick as an example.

[attachment=186872,3457]

Attachments:
  1. ledshematicsbb.jpg

March 1, 2012 | 4:13 pm

Even if I could just switch on the led with RFID without the dimmer would still be great.


March 1, 2012 | 9:36 pm

What Patrick says is correct, you need more than a simple SerialRead if you are using more than one serial input, and you should follow his link.

Do you specifically need Max for some reason? You can just use RFID and Arduino to switch on the LED and then hook up a potentiometer to dim.

Me and Arduino are a bit rusty, but this might be how to switch on the LED with RFID (obviously replace desiredTagNumber with the tag ID you are using):

char val = 0; //variable to store the data from the serial port

void setup() {
Serial.begin(9600); //connect to the serial port
}

void loop() {
if (Serial.available() > 0) {
val = Serial.read();
if (val == desiredTagNumber){
digitalWrite(9, HIGH);
}
}
}


March 3, 2012 | 6:06 am

Yeah tried that bit of code but no joy. I need to use MAX as my project relies on using my phone to control the light. I have a RFID chip on the back so I need to scan, light turns on then phone control light. I just can’t get RFID, led high, and the dimmer working together. does anybody know a quick read tag, turn on led, read tag turn off led. I have tried using processing too but with no joy. It is like making a Frankenstein RFID light. any more help would be amazing. been spending weeks on this. is there any way to get RFID and Maxuino working together?? I can make them all work great individually but I want my Demo to be consistent without opening up new codes and attaching new Arduinos.

Thanks so much for the replies so far.

Keenbop


March 3, 2012 | 8:16 pm

OK, personally if I wanted to do this, I would still do it all on Arduino. I would use a wifi enabled Arduino (wifi shield or something like the diamondback or hydrogen from DIY sandbox) and then either:

1. serve a webpage from the arduino that enables you to control the light from a browser on your phone
2. use an OSC app like TouchOSC and send OSC to the wifi arduino to control the light

There are tutorials for doing exactly these things on the DIYsandbox website, and the Asynclabs website and the Arduino forum.

This leads me to wonder why you need RFID too? Isn’t an on/ off button on the phone interface enough? If you really want to use Max, then you are going to have to follow the advice you were given and examine your serial issues.

If you mention the problems you get with the code I gave you then I/ someone else might be able to help you, though you might want to head over to the Arduino forum.


Viewing 7 posts - 1 through 7 (of 7 total)