Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 48
61  Forum 2005-2010 (read only) / Syntax & Programs / Re: Modifying "blink without delay" on: April 06, 2008, 02:21:26 pm
That's not uncommon, and you'll be wanting to use a counter inside the loop, rather than delays.  
62  Forum 2005-2010 (read only) / Syntax & Programs / Re: RFID code on: February 10, 2008, 10:43:04 pm
Sorry, that was wrong - give this a whizz

Code:
// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic


int  val = 0;
char code[10];
int bytesread = 0;

void setup() {

Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(2,OUTPUT);   // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
 digitalWrite(2, LOW);                  // Activate the RFID reader
}




 void loop() {

  if(Serial.available() > 0) {          // if data available from reader
    if((val = Serial.read()) == 10) {   // check for header
      bytesread = 0;
      while(bytesread<10) {              // read 10 digit code
        if( Serial.available() > 0) {
          val = Serial.read();
          if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
            break;                       // stop reading
          }
          code[bytesread] = val;         // add the digit            
          bytesread++;                   // ready to read next digit  
        }
      }
      if(bytesread == 10) {              // if 10 digit read is complete
        Serial.print("TAG code is: ");   // possibly a good TAG
        Serial.println(code);            // print the TAG code
      }
      bytesread = 0;
           delay(500);                       // wait for a second
    }
  }
}
63  Forum 2005-2010 (read only) / Syntax & Programs / Re: RFID code on: February 10, 2008, 10:31:12 pm
Code:
// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic


int  val = 0;
char code[10];
int bytesread = 0;

void setup() {

Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(2,OUTPUT);   // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
}

void activateReader() {
 digitalWrite(2, LOW);                  // Activate the RFID reader
}


 void loop() {

  if(Serial.available() > 0) {          // if data available from reader
    if((val = Serial.read()) == 10) {   // check for header
      bytesread = 0;
      while(bytesread<10) {              // read 10 digit code
        if( Serial.available() > 0) {
          val = Serial.read();
          if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
            break;                       // stop reading
          }
          code[bytesread] = val;         // add the digit            
          bytesread++;                   // ready to read next digit  
        }
      }
      if(bytesread == 10) {              // if 10 digit read is complete
        Serial.print("TAG code is: ");   // possibly a good TAG
        Serial.println(code);            // print the TAG code
      }
      bytesread = 0;
           delay(500);                       // wait for a second
    }
  }
}
64  Forum 2005-2010 (read only) / Syntax & Programs / Re: software serial interupt?? on: October 03, 2007, 01:26:44 pm
All readers do this, they assume a TAG will eventually be present to read, did you discover a cure?
65  Forum 2005-2010 (read only) / Syntax & Programs / Re: perhaps a little help with servo control?? on: September 02, 2007, 04:08:37 pm
Q. Was the supply adequate to power all 9 servo's ?
66  Forum 2005-2010 (read only) / Interfacing / Re: php Serial Class on: April 17, 2008, 03:45:07 pm
Here - I've included the mac version as well smiley

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1185507207/51#51

OSX is "DARWIN" btw
67  Forum 2005-2010 (read only) / Interfacing / Re: LEDS and 74HC595 shift register on: April 09, 2008, 07:47:50 am
Quote
John, I agree that if one wants to do more than run the example code, the learning curve in Processing is unnecessarily awkward. The Processing documentation is not very well organized and by the time I got an answer to a simple newbie question on the Processing forum, 3 or 4 days had gone by so I had bodged my own solution.

But for those that want to write code on a PC that talks to an Arduino and they don't know another language (or already know java) then Processing is worth a look. It's a shame that despite its family resemblance to the Arduino, Processing seems nowhere near as user friendly.

I agree absolutely, the IDE is very familiar and not a bad place to start. I also asked numerous questions at their forum when I first got an Arduino, some got answered, some didn't, and nearly always there was a considerable passage of time involved.

It took a while before I realized the capabilities of processing were ideal for bench testing applications. More serious applications, though not overly intricate, require a stability such as that offered by php.

Unfortunately, there wasn't much reference here to php as an alternative to processing, and it took the eventual discovery of the php_serial class, plus a very good example at the communitymx site, to realize it was viable.  

So the material is there now for others to explore, all it needs is an Ajax routine to update the GUI whenever there's a serial event initiated by the Arduino - for example, if a button is pushed you want the web page to do something or display a response to that event without needing to refresh the page every (x) seconds, and Ajax is the perfect solution.

I've got a script here that I've used for displaying mySql table updates in real time without refreshing the page, I should be able to adapt it to update elements on a web page in response to Arduino serial events, so it would be possible to monitor environmental sensors in real time from a web page over the www, without the page re-loading every 5 seconds.

In the button example, it's addressing a segment of an image using css sprites to display two button states (ON/OFF), so the same method can be applied for displaying segments of a bar graph, an analog meter, or a digital display like an LCD panel.  

So I might start with a PIR, and see if I can get a graphic to blip whenever it's tripped smiley  
68  Forum 2005-2010 (read only) / Interfacing / Re: LEDS and 74HC595 shift register on: April 09, 2008, 05:02:31 am
Quote
Quote
It's easier with php, processing doesn't provide a method to catch errors, instead, it throws exceptions and stops, ...

Hi John, are you sure? I haven't tried it but I would think you could do something like this in Processing:

try{
     somethingDodgy(); // a function that could fail
} catch (Exception e){
     safetyNet();   // this should be called if there is an exception in somethingDodgy()
}


Looks promising, but like I said, if you know your way around Java, which I don't, it's perhaps not a problem.

Try finding a solution to "NullPointerException" - I got invited to "contribute" the solution if I ever came up with one. And that's the other problem with processing, it's a one man band, and he's a very busy person. Questions and issues go unanswered in the forum, sometimes for days, weeks, months, and sometimes not at all. And that can result in stalled projects if you've built a framework that involves processing, only to hit a problem that you eventually discover, has no solution.

There's way more support for php, and with php_serial.class.php, most of the hard work has already been done. And particularly for use on the web, you can parse xhtml and css, and build nice 'all browser/platform compatible' clean 'standards compliant/device independent' web2.0 front ends.

I could never figure out how you'd make anything look nice using processing, so the php_serial.class was a very lucky find - particularly the OSX compatible version smiley

The only draw-back is, you need to do a crash course on setting up a LAMP stack, I've "read" it's something of a feat on Linux, and XAMPP on Windows XP, just looks out of place, lol.

MAMP on OSX was a breeze, it took under half an hour to set up, then to make it visible on the www, took another half an hour reading through the modem documentation.

The other good thing about a LAMP stack, is that you can install it on ITX motherboards (with XP&HDD), and that's a full Apache server on a low-powered mini computer, 802.11 wifi enabled, which provides an inexpensive long range web-accessible real-time physical computing platform.

Add a few dualCoreDuino's, and your robot gets wings *lol*
69  Forum 2005-2010 (read only) / Interfacing / Re: LEDS and 74HC595 shift register on: April 09, 2008, 02:46:01 am
It's easier with php, processing doesn't provide a method to catch errors, instead, it throws exceptions and stops, which is maybe fine if you know your way around java. It's also "just" php, a bit of xhtml & css for the API, and a LAMP stack for running the script on your local host, and then making that host accessible to the outside world, usually by creating a DMZ on your router/modem and port forwarding 8888 (the MAMP default).

The "php_serial_class", is excellent, particularly if you've got experience with php you'll be very comfortable creating web accessible real-time physical computing applications, complete with attractive css/xhtml/ajaxified API's

The php serial class can be downloaded here:-

http://www.modxhost.com/php_serial.class.txt

You'll need to change the extension to .php, or copy/paste the code into a blank document, and save it as php_serial.class.php

It can be used on Windows/Linux "and" this is the OSX compatible version.

Here's the php script which uses the class:-

http://www.modxhost.com/php-arduino-led-example.txt

Again, you'll need to change the extension to .php, and rename the file to something shorter like example.php

The button sprite used by the embedded css, can be downloaded here:-

http://www.modxhost.com/rocker_79x62.gif

I've used a CSS sprite so two buttons (ON/OFF) are loaded on the first instance the class is used.

And, here's the Arduino code (a quick hack) for toggling a LED. The Arduino is connected via USB to the computer that has the LAMP stack.

http://www.modxhost.com/arduino-code-4-php.txt

Here's an excellent tutorial on how to use the class, although, the class used isn't the OSX version - no big deal if your not using a mac smiley

http://www.communitymx.com/content/article.cfm?page=2&cid=8658A


70  Forum 2005-2010 (read only) / Interfacing / Re: LEDS and 74HC595 shift register on: April 08, 2008, 02:30:18 am
Quote
What would be really nice is modifying this so it stores the data from the text file in the EEPROM.  You can program the LED display off the PC and then run it independently.

Apologies. My 'subscribe to thread' somehow got substituted with another thread, so I've been getting notifications about the "encoder" project  ;D

Yes, an EEPROM would be an excellent elaboration. However, I've since dumped using processing entirely, and now use php via the php_serial library. It's awesome. A full web interface with patterns stored in a mySql database, communicating in real-time with an Arduino connected by USB.

I'll post a tutorial when I get some free time.

71  Forum 2005-2010 (read only) / Interfacing / Re: LEDS and 74HC595 shift register on: March 31, 2008, 05:19:41 pm
Quote
This is killing me... am I missing the serial library or something ?? (i don't think I am)

Trying to read an external .txt file just like Ryan's sketch but can't compile past this:

import processing.serial.*;
Serial port;

returning this error:

error: 'import' does not name a type

Any ideas?

What version of processing are you using? and what code snippet? This post is quite old, and I no longer have the code or processing for that matter.

Processing refers to this IDE.

http://www.processing.org/download/index.html

I'm not sure if this is the same snippet.

Code:
/* http client
 original code by Tom Igoe
 Starts a network client that connects to a server on port 80,
 sends an HTTP 1.1 GET request.
 Sends an input value to php
 php writes the value to a text file on a web server
  */
import processing.net.*;
Client client;
int inputValue = 33;                    // number representing the input switch - this would be determined by the value Arduino sends to processing

void setup()
{
  // open a TCP socket to the host:
  client = new Client(this, "yourserver.com", 80);
  // send the HTTP GET request:
  client.write("GET /~youraccount/switch.php?receivedValue=" + inputValue + " HTTP/1.1\n");
  client.write("HOST: yourserver.com\n\n");
   println("\n\nSend complete\n");
}

 
72  Forum 2005-2010 (read only) / Interfacing / Re: LEDS and 74HC595 shift register on: December 31, 2007, 04:45:27 pm
Quote
just wanted to say good job on all your work put into this.  Keep it up

Ryan

 ;D

Thanks, the project forked into something else quite a number of months ago but was useful for putting the 595 through its paces, now I look back on the code, it's really quite hard to follow.

So it's important to read this tutorial first:

http://www.arduino.cc/en/Tutorial/ShftOut22

There's code examples that explain how to start off with 1 register, then 2.

The key to lighting up all 16 LEDs, while really only having 8 on at a time, is this loop:

Code:

  digitalWrite(latchPin, 0); // ground the latchpin
  shiftOut(dataPin, clockPin, 255); // 1st register ignite all 8 LEDs
  shiftOut(dataPin, clockPin, 0);    // 2nd register turns off all 8 LEDs
  digitalWrite(latchPin, 1); // return the latch pin high

  digitalWrite(latchPin, 0); // ground the latchpin
  shiftOut(dataPin, clockPin, 0); // 1st register turns off all 8 LEDs
  shiftOut(dataPin, clockPin, 255);    // 2nd register ignite all 8 LEDs
  digitalWrite(latchPin, 1); // return the latch pin high

Because of the speed, the human eye will only see 16 LEDs turned on, while really there is only power going to 8 LEDs. Adding extra 595's to expand on the number of LEDs, while still only having 8 LEDs powered at any one time (thus not blowing up the Arduino), is done per:

Code:

  digitalWrite(latchPin, 0); // ground the latchpin
  shiftOut(dataPin, clockPin, 255); // 8 on
  shiftOut(dataPin, clockPin, 0);    // 8 off
  shiftOut(dataPin, clockPin, 0);    // 8 off
  shiftOut(dataPin, clockPin, 0);    // 8 off
  digitalWrite(latchPin, 1); // return the latch pin high

  digitalWrite(latchPin, 0); // ground the latchpin
  shiftOut(dataPin, clockPin, 0); // 8 off
  shiftOut(dataPin, clockPin, 255);    // 8 on
  shiftOut(dataPin, clockPin, 0);    // 8 off
  shiftOut(dataPin, clockPin, 0);    // 8 off
  digitalWrite(latchPin, 1); // return the latch pin high

  digitalWrite(latchPin, 0); // ground the latchpin
  shiftOut(dataPin, clockPin, 0); // 8 off
  shiftOut(dataPin, clockPin, 0);    // 8 off
  shiftOut(dataPin, clockPin, 255);    // 8 on
  shiftOut(dataPin, clockPin, 0);    // 8 off
  digitalWrite(latchPin, 1); // return the latch pin high

  digitalWrite(latchPin, 0); // ground the latchpin
  shiftOut(dataPin, clockPin, 0); // 8 off
  shiftOut(dataPin, clockPin, 0);    // 8 off
  shiftOut(dataPin, clockPin, 0);    // 8 off
  shiftOut(dataPin, clockPin, 255);    // 8 on
  digitalWrite(latchPin, 1); // return the latch pin high
 

You can downsize this code using variables and counters.

I had 8 595's wired up to ultra high powered LEDs and this worked fine, I don't think there's a limit to the number of 595's you can piggy-back, so for cost its an economic solution to controlling large numbers of LEDs, you can buy 10 off a number of eBay sellers for just a few bucks smiley


73  Forum 2005-2010 (read only) / Interfacing / Re: LEDS and 74HC595 shift register on: December 06, 2007, 08:00:29 am
Mac + Photoshop 7, the wires were done as paths, the rest was hacked from the tutorial images, not an off-the-shelf solution I'm afraid.
74  Forum 2005-2010 (read only) / Interfacing / Re: LEDS and 74HC595 shift register on: September 27, 2007, 07:44:11 pm
Quote
Quote
u mean 74HC595 ?

two leds is not a problem, you won't be needing the resistor, remember there's only ever 1 pin lit up at a time, so you could probably stack 10 LEDs on 1 pin x 8 pins (80) because there's only ever 10 LED's on at one time, going through pins in a cycle that's too fast for the human eye to discern.

 

What do you mean by one at a time?.. 74HC595 has latch ...latch clock is different than serial input clock. I can load the register and then command output for all of them.

My parallel scheme was something like this


            -----LED-------
            |                  |
VCC --- |                  |-----RES---- 74HC595
            |                  |
            -----LED-------


Since one LED need 10mA the current flowing through 74HC595 will be 20mA.
I set all latch bits to 0V and all leds light up at a time



There's never any more than 1 pin on at a time, so the total amps used is only the sum of 1 pin, of course you control all 8 of them, it's an 8-bit serial in serial or parallel out shift register.            

And you don't need the resistor if your using more than one LED, the resistors only there to stop the LED from frying out, with two LED's it's enough to not need the resistor.




            -----LED-------
            |                  |
GND --- |                  |------------ 74HC595
            |                  |
            -----LED-------


I've got 3 595's driving 24 LED's and 5 relays piggy-backed on top of 5 of the LED's, the LEDs over the relays don't need resistors, and I'm using those evil MCD 10000 high-bright green LED's, they shine as bright with 1 595 and 8 LEDs, or 3 of them and 24 LEDs plus the relays.
75  Forum 2005-2010 (read only) / Interfacing / Re: LEDS and 74HC595 shift register on: September 27, 2007, 02:50:47 pm
u mean 74HC595 ?

two leds is not a problem, you won't be needing the resistor, remember there's only ever 1 pin lit up at a time, so you could probably stack 10 LEDs on 1 pin x 8 pins (80) because there's only ever 10 LED's on at one time, going through pins in a cycle that's too fast for the human eye to discern.

Pages: 1 ... 3 4 [5] 6 7 ... 48