Show Posts
Pages: 1 ... 100 101 [102] 103 104 ... 354
1516  Using Arduino / Programming Questions / Re: Multiple Data, Clock, Latch pins on: October 28, 2013, 09:05:20 am
Can't the SS be chained one to the next? CLK to CLK, MISO of each shift register goes to MOSI of the next, last MOSI to the AVR MISO (or don't bother, but you could cycle bytes) and SS latches the whole chain at once. With power and ground, 6 wires should do the set.

I've read here that an UNO should be able to hit 2 MB/sec (16Mb/sec) on SPI. Is that wrong?

1517  Using Arduino / Programming Questions / Re: Hello World Not Working on: October 28, 2013, 08:53:09 am
I couldn't even get a text thro serial monitor.

What I posted is for the person who started this topic, which is NOT THE SAME AS YOURS.

If you want help, start a NEW TOPIC. Use the forum button that says NEW TOPIC. Every section of the forum has one near the top on the right side.

If you can't read and follow this then who can help you anyway?
1518  Using Arduino / Programming Questions / Re: Hello World Not Working on: October 28, 2013, 08:08:29 am
I dunno wat mistake i've done?

Really you should start a new topic instead of walking all over the original poster's question. It will get you better help sooner.


If you can't read and understand, make a NEW TOPIC to get help, then how can anyone explain simple things like code?

Go back to Programming Questions and find near the top the words NEW TOPIC. Click that button and start your own thread. It is not good to jump in an unrelated thread (truly a different problem) like this one and ask for attention. Here we try to help Jazzman81. In the topic that YOU make, we try to help YOU.
 
1519  Using Arduino / Programming Questions / Re: Hello World Not Working on: October 28, 2013, 07:59:03 am
I installed Arduino 1.0.5 today and i cant get it to compile anything. I've installed on a Windows 7 Laptop and a Mac Book and neither of them compile the code below. I'm trying the most basic code:

println("Hello World!\n");

With the Arduino on USB cable to your PC you can get it to send Hello World!\n to a serial terminal program such as Serial Monitor included in your IDE. Just make sure that you open Serial Monitor which resets the board.

Code:
void setup()
{
  Serial.begin( 9600 ); // make sure that Serial Monitor is set for 9600 baud or change this to match it
  Serial.println( "Hello World!\n" ); // prints Hello World! and then 2 new lines
}

void loop()
{
  // loop does nothing here. Press reset to get it to print Hello World!\n again.
}

With Processing and the Serial library you can catch that message rather than using Serial Monitor.
Arduino is a version of Wiring as in Processing and Wiring go together. Processing has setup() and draw(), Arduino has setup() and loop(). That is not by accident.

1520  Using Arduino / Programming Questions / Re: Hello World Not Working on: October 28, 2013, 07:47:16 am
I dunno wat mistake i've done?

Really you should start a new topic instead of walking all over the original poster's question. It will get you better help sooner.
1521  Using Arduino / Programming Questions / Re: I'm having problems with long var acting as int variable. on: October 28, 2013, 07:38:45 am
I'm using the time library and want to start at 0 seconds for each day. After one day, I want to reset the time back to zero. I know I'll want to add in more days, but for now this is what I'm looking for.

I don't know this time library as I've never needed it. There is a simple and direct way that will let you set intervals up to 49.71 days in milliseconds without going to 64-bit integers. The example code is in your IDE under the name BlinkWithoutDelay but it has some minor errors (doesn't use unsigned long for -all- the time variables) so here's a fixed copy:
Code:
/* Blink without Delay -- with UL fixes... 2013
 
 Turns on and off a light emitting diode(LED) connected to a digital 
 pin, without using the delay() function.  This means that other code
 can run at the same time without being interrupted by the LED code.
 
 The circuit:
 * LED attached from pin 13 to ground.
 * Note: on most Arduinos, there is already an LED on the board
 that's attached to pin 13, so no hardware is needed for this example.
 
 
 created 2005
 by David A. Mellis
 modified 8 Feb 2010
 by Paul Stoffregen
modified 2013 to make all the time variables unsigned long
 by GFS
 
 This example code is in the public domain.

 Without the 2013 fixes:
 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
 */

// constants won't change. Used here to
// set pin numbers:
const int ledPin =  13;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
unsigned long previousMillis = 0UL;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
unsigned long interval = 1000UL;           // interval at which to blink (milliseconds)

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

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

Learn this, understand what these few lines do and you have the key to multitasking on Arduino.

The big important part is:
Code:
  if(currentMillis - previousMillis > interval) {

In that unsigned subtraction you will ALWAYS get the difference from previous to current even through the dreaded rollover BECAUSE it is UNSIGNED subtraction. It is the same as looking at a clock and knowing that 1 o'clock is 2 hours after 11 o'clock. Unsigned math is like a clock.

Here is a sketch that you can use and modify to see just how unsigned math works:
Code:
unsigned long a, b, c;

void setup() {
  Serial.begin( 9600 );
  a = 0xffffff00UL;
  b = 0x10UL;
  Serial.println( "\n unsigned math\n" );
  Serial.print( "a = ");
  Serial.print( a, DEC );
  Serial.print( " = 0x");
  Serial.print( a, HEX );
  Serial.print( " = 0b");
  Serial.println( a, BIN );
  Serial.print( "b = ");
  Serial.print( b, DEC );
  Serial.print( " = 0x");
  Serial.print( b, HEX );
  Serial.print( " = 0b");
  Serial.println( b, BIN );
  if ( b >= a ) Serial.println( "b >= a" );
  else          Serial.println( "a > b" );
  c = a - b;
  Serial.print( "a - b = ");
  Serial.print( c, DEC );
  Serial.print( " = 0x");
  Serial.print( c, HEX );
  Serial.print( " = 0b");
  Serial.println( c, BIN );
  c = b - a;
  Serial.print( "b - a = ");
  Serial.print( c, DEC );
  Serial.print( " = 0x");
  Serial.print( c, HEX );
  Serial.print( " = 0b");
  Serial.println( c, BIN );
  c = b - (b + 1);
  Serial.print( "b - (b + 1) = ");
  Serial.print( c, DEC );
  Serial.print( " = 0x");
  Serial.print( c, HEX );
  Serial.print( " = 0b");
  Serial.println( c, BIN );
 
  while( 1 );
}

void loop() {};


So a day is 24UL * 60UL * 60UL * 1000UL; // the compiler pre-calculates, hours x minutes x seconds x millis.

UNO time is not exact and varies some with temperature. You can test how far off and use that to correct your interval values.

 
1522  Using Arduino / Programming Questions / Re: Clearing and setting pins at the same time on: October 28, 2013, 07:09:16 am
You only get data when you read. So don't read until you do the 2-step which btw is about as short as it gets.

If an interrupt might get the bad data then disable interrupts with cli(), set the port and enable interrupts with sei().

Note that most commands execute in a cycle or two though some functions have lots of overhead and may take more than a microsecond to run. Is your code so time critical that that is a problem?
 
1523  Using Arduino / Programming Questions / Re: Should i use a new "While loop" or just use "if statements"? on: October 28, 2013, 06:58:01 am
Arduino IDE has 2 required functions, setup() and loop().

In setup() you put the things that only run once.
In loop() you put your real time code that deals with events and allows multitasking.
http://www.gammon.com.au/forum/?id=11411

You can also include libraries, #define values, declare variables, and add other functions outside of setup() and loop() though if you want variables inside loop() to hold their values, you must declare them as static.

Your while( 1 ) is like trying to make loop() when you don't know it's there.

What you should do for your robot is make a finite state machine.
1524  Using Arduino / Programming Questions / Re: counting state change in analog input on: October 28, 2013, 06:45:20 am
You can use delayMicroseconds() to get it finer but be aware the 'granularity' is 4 usecs, not 1.

Down the road in your learning you should learn to not use blocking code (delay) but have things trigger on time instead. Blocking code makes everything hold up for one thing, using non-blocking code allows many things to "happen at once".

Here's the best/clearest explanation I've seen and a sample superior to BlinkWithoutDelay:
http://www.gammon.com.au/forum/?id=11411

1525  Using Arduino / Programming Questions / Re: How to send multiple data values from many potentiometers via RF links? on: October 27, 2013, 03:46:42 pm
You need to get that solved first. The code you have -depends- on flawless transmission.



ok so it's simply the problem ?
i must get the antenna the same exactly dimensions they as for these links ?


That's not the only problem but until you fix it nothing else can be reliably done.
This is a step in troubleshooting. Remove errors and causes of errors one at a time. Change only ONE thing at a time so you get fewer mixed results to misinterpret.

The antenna do not have to be exact.
1526  Using Arduino / Programming Questions / Re: counting state change in analog input on: October 27, 2013, 03:39:34 pm
Your threshold and time are both way too high and I am guessing it's because you try and use them to fix what you don't understand. The code itself prints count with every loop inside the time window. You should expect repeats. The print should only be when time is up.

The delay which should only get an integer, not a float, is giving the board time to send the print message.

Try put the threshold back to 800 and time... you need work there to be able to take more than one reading without reset the board but do that later.
1527  Using Arduino / Programming Questions / Re: How to send multiple data values from many potentiometers via RF links? on: October 27, 2013, 03:16:48 pm
You need to get that solved first. The code you have -depends- on flawless transmission.

1528  Using Arduino / Programming Questions / Re: counting state change in analog input on: October 27, 2013, 04:08:43 am
How many times the pot went 800+ and back is not the same as how many times the pot was read as being 800 or more.

1529  Using Arduino / Programming Questions / Re: How to send multiple data values from many potentiometers via RF links? on: October 27, 2013, 03:53:08 am
Because you want to copy the contents of buf (uint8_t) into a char array. If you tried to use buf directly, it would give errors.
So you need to make sure you have enough space to copy the data. And data[ i ] = buf[ i ] is easy to understand. You could probably also use strcpy();

ok thank you i will need to read more about this subject it's complicated

Not as complicated as it might appear to you right now. You lack "literacy" and when you hit terms or practices you don't know it's like a wall. That's why you should find and go through tutorials and make small test programs to see if what you think is enough for that bit. I do those myself and sometimes post examples, just something inside setup() with no code in loop that sets up variables, does a command and prints results all simple and no doubt. If you're not sure of a command, make a test sketch and modify it until you are sure or know better -what- to ask.

uint8_t -- the t is for type (variable type), the u is for unsigned (0+ values only), the int is for integer and the 8 is for 8 bits. Arduino has another name for those, byte. A char is the signed version. You can print chars and you can 'cast' a byte to a char to print it or an array of it (bytes cast to char).
Cast-ing is a C mini-subject. It is how to change the way the compiler uses variables. If you haven't then google on C variable tutorial and spend some time there or maybe pick it up out of the Arduino pages.

This is the Arduino Tutorials Page in the Learning section:
http://arduino.cc/en/Tutorial/HomePage

See near the top it says "Learning   Examples | Foundations | Hacking | Links". That link is the Examples part. The examples, btw, are all in your IDE through the File popdown menu. You also want to explore the Foundations link to pick up on basics.

Above that on the green-blue bar you see Buy Download Products Learning Reference Support Blog
You are in Learning. When you get done with that (and web searched tutorials to help when you need) then go to the Reference link and explore what's there. And still you'll need tutorials, the Arduino site has not everything including C strings but instead shows Examples with C++ String objects which are better not used on Arduino.
1530  Using Arduino / Programming Questions / Re: Writing Text file on SD on: October 26, 2013, 03:18:13 pm
http://arduino.cc/en/Reference/SDopen

Quote
mode (optional): the mode in which to open the file, defaults to FILE_READ - byte. one of:

    FILE_READ: open the file for reading, starting at the beginning of the file.
    FILE_WRITE: open the file for reading and writing, starting at the end of the file.

Pages: 1 ... 100 101 [102] 103 104 ... 354