Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Number (1-127) to control 7 IO on: June 07, 2008, 10:14:33 pm
Yeah, I'm dumb and didn't set the pins as outputs. And I was being lazy and not using limiting resistors. I guess I'll change that.

EDIT: Oh yeah, Thanks both of you!
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Number (1-127) to control 7 IO on: June 07, 2008, 05:30:18 pm
So I used your technique, bens, and it seemed to work, except that only the LEDs on pins 12 and 13 were bright. The rest were very dim. I have standard red LEDs wired directly from the arduino outputs, no resistors. It is powered off of the usb port. Is it a power problem, or something else?
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Number (1-127) to control 7 IO on: June 07, 2008, 01:56:26 pm
Do I have to modify the code to work up to 127 and with 7 pins? Also, can I just put a number for the starting pin, like this:
Code:
digitalWrite(4+3-x, ((code & int(pow(2,x))) ? HIGH : LOW));
4  Forum 2005-2010 (read only) / Syntax & Programs / Number (1-127) to control 7 IO on: June 07, 2008, 10:49:50 am
Ok, I have a program on my PC that sends a number from 1 to 127, to tell the arduino what pins to activate. the key goes like this:
     Pin 13 = 64
     Pin 12 = 32
     Pin 11 = 16
     Pin 10 = 8
     Pin 9 = 4
     Pin 8 = 2
     Pin 7 = 1

So if the PC sends 127, all pins are on.
I have code that works for the first two, but would be messy to implement more. I was wondering if there were any shortcuts to getting the pin control information out.

Code:
char serInString[100];  // array that will hold the different bytes of the string. 100=100characters;
                        // -> you must state how long the array will be else it won't work properly
char colorCode;
int colorVal;
int x;

int outputPin = 13;
int outputPin2 = 12;

void setup() {
  pinMode(outputPin, OUTPUT);
  pinMode(outputPin2, OUTPUT);
  Serial.begin(9600);
}

void loop () {
  //read the serial port and create a string out of what you read
  readSerialString(serInString);
  colorVal = atoi(serInString);
  serInString[0] = 0;
  serInString[1] = 0;
  serInString[2] = 0;
  serInString[3] = 0;  
  Serial.println(colorVal, BIN);
    if (colorVal - 64 >= 0) {
      digitalWrite(outputPin, HIGH);
      colorVal = colorVal - 64;
        if (colorVal - 32 >= 0) {
      digitalWrite(outputPin2, HIGH);
      colorVal = colorVal - 32;
        }
        else if (colorVal - 32 < 0) {
      digitalWrite(outputPin2, LOW);
        }
    }
    else if (colorVal - 64 < 0) {
      digitalWrite(outputPin, LOW);
      if (colorVal - 32 >= 0) {
      digitalWrite(outputPin2, HIGH);
      colorVal = colorVal - 32;
        }
        else if (colorVal - 32 < 0) {
      digitalWrite(outputPin2, LOW);
    }
    }
  delay(100);  // wait a bit, for serial data
}

//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray) {
  int i = 0;
  if(!Serial.available()) {
    return;
  }
  while (Serial.available()) {
    strArray[i] = Serial.read();
    i++;
  }
}
5  Forum 2005-2010 (read only) / Syntax & Programs / converting delay code to interrupt:Metronome on: September 04, 2007, 07:25:40 pm
I have some code for a metronome that I wrote, currently set by variable. It calculates a delay value, and blinks an LED. Here it is:
Code:
int ledPin = 13;                 // LED connected to digital pin 13
int val = 0;                     // variable for reading the pin status
int del = 126;
int delval = 0;

int calc(int val)
{
  val = val / 60;        //Gets BEats per second
  val = 1000 / val;    //Gets Milliseconds for delay
  val = val - 71;        //value obtained by guess and check for LED time
  return val;
}

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()
{
  delval = calc(del);
  digitalWrite(ledPin, HIGH);  // sets the LED on
  delay(50);                   // waits for a second
  digitalWrite(ledPin, LOW);   // sets the LED off
  delay(delval);                  // waits for a second
}



I would like to turn this into a program that uses interrupts, so that it exandable. Ex. Potentiometer,LCD, piezo output

The only problem is that I can't figure out how to apply timer interrupts. I have searched for a while, so I figured I'd ask the forum for help.
6  Forum 2005-2010 (read only) / Interfacing / Arduino dll? on: June 06, 2008, 10:31:16 am
I thought that a good project that could benefit the community would be to create a dll(VC#?) that would allow an arduino running the serialio firmware to act as a k8055 board. The K8055 is a usb board with 5 digital inputs, 8 digital outputs, 2 analog inputs, and 2 analog outputs. The Arduino board fists most of these specifications, and is much less expensive. If I am correct, all it would require would be making a class in VC# with the same functions as the dll(Found on velleman's site), only converting the commands to serial commands and sending them to the arduino.

Links:http://www.velleman.be/ot/en/product/view/?id=351346 K8055 board
        http://userwww.sfsu.edu/~infoarts/technical/arduino/wilson.arduinoresources.html Arduino Firmware
        http://www.vellemanusa.com/us/enu/download/files/ vellman dll and examples

I've started working on it, and I was wondering if anyone had any experience in making DLL files.
7  Forum 2005-2010 (read only) / Interfacing / Re: Multiple byte serial input on: February 12, 2008, 08:24:16 am
I must be able to send data to it from a serial terminal, so it must be something I can type on a standard keyboard. I know binary pretty well, so I could handle that, but I still don't know how to implement it.
8  Forum 2005-2010 (read only) / Interfacing / Multiple byte serial input on: February 10, 2008, 12:36:52 pm
I have been scrounging the web for a way to send multiple bytes from my PC to my arduino. I need to be able to send a number( number of sensor counts) ranging from 1 to 1,000, or maybe more. I need this data to be usable as if I had said:

volatile int Dists = 65;

on the arduino
(It is volatile because it needs to be used in an interrupt)

Please Help!
9  Forum 2005-2010 (read only) / Interfacing / Re: Connecting Arduino to iPhone/iPod serial on: October 13, 2008, 08:44:06 pm
I did this with my ipod touch jailbreaked 2.0.2. Hardware wise I used a cable from :http://www.rush2112.net/mkportal/modules/oscommerce/product_info.php?products_id=34&osCsid=623417921d61d5ff5d81100e93fc1cf6, although they used to just sell the ipod to 8-din cable. Tx from ipod goes straight into Arduino, While Rx goes through 1k resistor(3.3v). Software wise I have accomplished three different things:

1. Using Minicom from the Cydia installer to talk like a terminal.

2. Use a GPSShield from Ladyada to get NMEA GPS data into xGPS, also found in Cydia.

3. Used Iphone/Python and this:http://www.elifulkerson.com/projects/telnet-serial-bridge.php as a Wifi Serial port, through which I could control a simple servo robot with this: http://www.jbprojects.net/projects/wifirobot/

If you would like me to elaborate on any of these, just ask. It was a little while ago, but I can still try and help.
10  Forum 2005-2010 (read only) / Interfacing / Re: "Go" Button on: March 16, 2008, 02:03:40 pm
Nevermind, I fixed it. I did put an LED blink in there, but you forgot the brackets after the while statement. Its all good, and it works now. Thank you.
11  Forum 2005-2010 (read only) / Interfacing / Re: "Go" Button on: March 16, 2008, 01:13:27 pm
This doesn't seem to be working for me. I apply power, wait ~ 10 sec. (I have an NG rev.c) and press the button, and nothing happens? All I added was a switch between pin 8 and ground. I didn't think I needed to pull it up since you used the internal pullups.

PS. I know the delay isn't ideal, but I will be turning the system off shortly after it stops, so I don't really worry about it.
12  Forum 2005-2010 (read only) / Interfacing / "Go" Button on: March 16, 2008, 10:35:54 am
I need to put a button in my arduino that will pause all code until the button is pressed.
I need to not let the pin in the loop turn on, until a switch is pressed. After that, the switch doesn't matter at all.
Here is my code:
Code:
int pin = 9;
int ledPin = 13;
volatile int state = LOW;
volatile int Count = 0;
volatile int Dists = 65;

void setup()
{
  pinMode(pin, OUTPUT);
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  attachInterrupt(1, Dist, FALLING);
}

void loop()
{
  digitalWrite(pin, HIGH);
}

void Dist()
{
  Count++;
  if (Count >= Dists)
  {
    digitalWrite(pin, LOW);
    digitalWrite(ledPin, HIGH);   // sets the LED on
    delay(100000);    
  }
}
13  Forum 2005-2010 (read only) / Interfacing / Re: arduino programming on-the-go on: January 31, 2008, 06:59:22 am
I looked at that code, and will it compile and go right on the arduino, or is it just a function. It has no Setup or loop functions, so I wondered what else it would take to run it.
14  Forum 2005-2010 (read only) / Interfacing / Re: arduino programming on-the-go on: January 30, 2008, 08:24:39 pm
Sorry to bump/double post, but I have another question. I changed my mind yet again, and decided to us an HP 100lx as the terminal. The problem is that the device can only send one byte at a time. Here is my test code:
Code:
int incomingByte = 0;      // for incoming serial data

void setup() {
      Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps
}

void loop() {

      // send data only when you receive data:
      if (Serial.available() > 0) {
                Serial.println("Type in a Number");
            // read the incoming byte:
            incomingByte = Serial.read();

            // say what you got:
            Serial.print("I received: ");
                Serial.println(incomingByte, BYTE);

      }
}
Every time I press a key, the arduino returns with that value. But, If I use the serial monitor in the arduino software, It still sends the data back one byte at a time. I need to send a number, 4-5 characters long, and Have it save to a variable.
15  Forum 2005-2010 (read only) / Interfacing / Re: arduino programming on-the-go on: January 15, 2008, 04:50:29 pm
I was considering using serial, but I don't have any easily accessible portable serial terminal devices. I know my PSP, ipod touch, and old Ipaq pda have serial ports, but none(except maybe the ipaq) have serial terminal software. Right now I am leaning towards the IR remote programming. I have many salvaged 38khz IR receivers, so I will be trying that tonight.

Also, I have my revised code. It works, reading an IR wheel encoder and controlling the distance of the vehicle. I am building it for the http://soinc.org/events/sample/ElectricVehicle_C08_v13%20_1_.pdfElectric Vehicle event in the Science Olympiad.

Code:
int pin = 9;
int ledPin = 13;
volatile int state = LOW;
volatile int Count = 0;
volatile int Dists = 65;

void setup()
{
  pinMode(pin, OUTPUT);
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  attachInterrupt(1, Dist, FALLING);
}

void loop()
{
  digitalWrite(pin, HIGH);
}

void Dist()
{
  Count++;
  if (Count >= Dists)
  {
    digitalWrite(pin, LOW);
    digitalWrite(ledPin, HIGH);   // sets the LED on
    delay(100000);    
  }
}


EDIT: I just changed my mind. Iam in the process of obtaining a cybiko classic device, which has a built in serial port and keyboard, and you can easily uase it as a portable serial terminal.
Pages: [1] 2