Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Interfacing w/ Software on the Computer / Re: Arduino + Processing for Graphing on: June 12, 2013, 01:12:07 pm
Thank you PaulS, that fixed my problem and it works. It was a little fast so I slowed it down by making it a 20 mS delay instead to the 2 mS delay they had - thanks again PaulS
2  Using Arduino / Interfacing w/ Software on the Computer / Re: Arduino + Processing for Graphing on: June 11, 2013, 07:17:10 pm
I forgot to post the code:

Arduino:

Code:
void setup() {
  // initialize the serial communication:
  Serial.begin(115200);
}

void loop() {
  // send the value of analog input 0:
  Serial.println(analogRead(A0));
  // wait a bit for the analog-to-digital converter
  // to stabilize after the last reading:
  delay(2);
}

Processing code:

Code:
import processing.serial.*;
 
 Serial myPort;        // The serial port
 int xPos = 1;         // horizontal position of the graph
 
 void setup () {
   // set the window size:
   size(400, 300);       
   // List all the available serial ports
   println(Serial.list());
   // I know that the first port in the serial list on my mac
   // is always my  Arduino, so I open Serial.list()[0].
   // Open whatever port is the one you're using.
   myPort = new Serial(this, Serial.list()[2], 9600);
   // don't generate a serialEvent() unless you get a newline character:
   myPort.bufferUntil('\n');
   // set inital background:
   background(0);
 }
 
 void draw () {
   // everything happens in the serialEvent()
 }
 
 void serialEvent (Serial myPort) {
   // get the ASCII string:
   String inString = myPort.readStringUntil('\n');
   
   if (inString != null) {
     // trim off any whitespace:
     inString = trim(inString);
     // convert to an int and map to the screen height:
     float inByte = float(inString);
     inByte = map(inByte, 0, 1023, 0, height);
     
     // draw the line:
     stroke(127,34,255);
     line(xPos, height, xPos, height - inByte);
     
     // at the edge of the screen, go back to the beginning:
     if (xPos >= width) {
       xPos = 0;
       background(0);
     } else {
       // increment the horizontal position:
       xPos++;
     }
   }
 }

3  Using Arduino / Interfacing w/ Software on the Computer / Arduino + Processing for Graphing on: June 11, 2013, 07:11:36 pm
I tried the following:

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

I put the arduino sketch in the same folder/directory as the processing sketch so when I verify the arduino sketch I get an error:

variable or field 'serialEvent' declared void.

So what am I doing wrong?
4  Using Arduino / Project Guidance / Re: REVERSE KNIGHT RIDER STYLE EFFECT- HOW TO SLOW DOWN on: May 24, 2013, 11:45:49 pm
This will solve your issues, if and only if I understand them(issues correctly), by looking at:

https://www.sparkfun.com/products/733

it's a Shift Register (8-Bit - 74HC595) ...you can "shift in" your data (which leds you want on or off)...you control them as how you like
5  Using Arduino / Project Guidance / Re: SRAM interface question on: May 24, 2013, 10:21:31 pm
Between oric_dan and aarondc's comments (thank you both) I've been able to get the following to work:
Code:
 for(int i=0; i<7; i++) {
    unsigned int rw_addr = exIntAry0+(i*sizeof(int));
    writeRamInt(i, rw_addr, sizeof(int));
  }

  for(int i=0; i<7; i++) {
    unsigned int rw_addr = exIntAry0+(i*sizeof(int));
    int numb = readRamInt(rw_addr, sizeof(int));
    Serial.print(F("numb= "));
    Serial.println(numb);
  }
The problem is, you have to program how many elements the array has...  ...any ideas on how to solve this issue?
6  Using Arduino / Project Guidance / Re: SRAM interface question on: May 23, 2013, 08:11:49 pm
thank you oric_dan, I can really use this info
7  Using Arduino / Programming Questions / Re: Passing arrays to functions on: May 14, 2013, 06:40:51 pm
or pass the information required as another parameter and use switch - case.
It doesn't sound like you would gain much from having one function with a switch statement VS two functions - one for ints and one for longs. ...but anyway, I guess you are saying pass another variable to the function to tell the switch statement to work on ints or longs - right?
8  Using Arduino / Programming Questions / Re: Strange behaviour when reading button on: May 14, 2013, 06:29:53 pm
try holding the button down for more than 500 mSec and see what happens - during the delay(500) it is blocking - might want to take a look at "blink without delay" http://arduino.cc/en/Tutorial/BlinkWithoutDelay
9  Using Arduino / Programming Questions / Passing arrays to functions on: May 14, 2013, 06:26:31 pm
In the code below, it has two functions called "changeIntArray()" and "changeLongArray()" which changes the contents of each array (int or long). Is it possible to write one function the could change both ints and longs?  The commented out area is what I tried and it didn't work.

Code:
#include <stdio.h>

void changeIntArray(int ary[], int size) {
int i;
for(i=0; i<size; i++) {
ary[i] = 0;
}
}

void changeLongArray(long ary[], int size) {
int i;
for(i=0; i<size; i++) {
ary[i] = 0;
}
}

/**************************************
void changeAnyArray(void ary[], int size) {
int i;
for(i=0; i<size; i++) {
ary[i] = 0;
}
}
/**************************************/
int main() {
int intAry[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
long longAry[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int i;

for(i=0; i<sizeof(intAry)/sizeof(int); i++) {
printf("intAry[%d]=%d \n", i, intAry[i]);
}
printf("\n\n");
changeIntArray(intAry, sizeof(intAry)/sizeof(int));
for(i=0; i<sizeof(intAry)/sizeof(int); i++) {
printf("intAry[%d]=%d \n", i, intAry[i]);
}

printf("\n\n\n\n");

for(i=0; i<sizeof(longAry)/sizeof(int); i++) {
printf("longAry[%d]=%d \n", i, longAry[i]);
}
printf("\n\n");
changeLongArray(longAry, sizeof(longAry)/sizeof(long));
for(i=0; i<sizeof(longAry)/sizeof(long); i++) {
printf("longAry[%d]=%d \n", i, longAry[i]);
}

printf("\n\n\n\n");

/**************************************
for(i=0; i<sizeof(longAry)/sizeof(long); i++) {
printf("longAry[%d]=%d \n", i, longAry[i]);
}
printf("\n\n");
changeAnyArray((long)longAry, sizeof(longAry)/sizeof(long));
for(i=0; i<sizeof(longAry)/sizeof(long); i++) {
printf("longAry[%d]=%d \n", i, longAry[i]);
}
/**************************************/
return 0;
}
10  Using Arduino / Programming Questions / Re: Error: undefined reference to `fn()' on: May 12, 2013, 01:48:55 pm
(DONT include the .c file in the header file!!!)

Relative to Jodes' first post, why is adding #include "test.c" in the header file a bad idea? When I did it, everything compiled without error.
11  Using Arduino / Programming Questions / Re: Error: undefined reference to `fn()' on: May 12, 2013, 01:41:42 pm
in test.h try

Code:
#include "test.c"
void fn();
12  Using Arduino / Programming Questions / Re: Why static function on: May 12, 2013, 01:08:09 pm
When a function is declared as static it is only available inside the c file where it is defined.

Thank you tobyb121 - now I understand
13  Using Arduino / Programming Questions / Why static function on: May 12, 2013, 12:16:23 pm
I got the follow code off of the internet:

Code:
static int bytesToInt(byte b0, byte b1) {
  return (int) (((int)b1 << 8) | ((int)b0 & 0xFF));
}

static void intToBytes(int num, byte *b0, byte *b1) {
  *b0 = (byte)(num & 0xFF);
  *b1 = (byte)((num >> 8) & 0xFF);
}

...and I don't understand why it was made static.  Shouldn't it work without static? In the first function it returns an int. In the second function it modifies bytes bo & b1 so why does it need to be static?
14  Using Arduino / Programming Questions / Re: Arduino IDE 1.0.3 serial monitor's screen will not re-size on: May 11, 2013, 12:57:34 pm
I searched the  preferences.txt file for "serial" and only thing I found was:
Okay so ADD the line then.

last.serial.location=51,22,500,500

Could installing HyperTerminal have something to do with it messing up the serial monitor's resize?
Only in the same way that launching Solitaire changes the current font you are using in Word.
Many many thanks James C4S - you fixed it
15  Using Arduino / Programming Questions / Re: Arduino IDE 1.0.3 serial monitor's screen will not re-size on: May 11, 2013, 12:43:35 pm
Regardless, fiddling with the COM port won't have any effect on the serial monitor's window size.  The serial monitor just talks to the serial port.  Since the window size is saved in the IDE's preferences.txt file, you can go and modify that.

Exit the IDE, search for "last.serial" and set it to something like:  
last.serial.location=0,0,500,500

Save and relaunch the IDE.
I searched the  preferences.txt file for "serial" and only thing I found was:

Code:
serial.port=COM1
serial.databits=8
serial.stopbits=1
serial.parity=N
serial.debug_rate=9600
...so that didn't work.   oh, sorry about the windoze comment, I was trying to make a funny comment on windows xp being so slow.
Any ideas on what to try now?  Could installing HyperTerminal have something to do with it messing up the serial monitor's resize?
Pages: [1] 2 3 ... 5