Show Posts
Pages: 1 2 [3] 4 5 ... 304
31  Using Arduino / Programming Questions / Re: Calculating slope using array issues on: April 18, 2014, 11:07:36 am
I should have taken more time on that.
32  Using Arduino / Programming Questions / Re: Sketch on Mini w/328 only runs once on: April 18, 2014, 11:05:09 am
Quote
You do know that the Mini may have some differences as to pin numbers (and is there a led?) from say, the UNO?
No it doesn't. It's the same 328P chip. Only difference is that some promini's support A6/A as analog inputs.


My UNO board has a pin map just to tell board pins from 328 pins.

Does the Mini have the built-in led and resistor on pin 13?
33  Using Arduino / Programming Questions / Re: Where am I going wrong with the no delay method? on: April 18, 2014, 11:01:19 am
If you use unsigned integers then the only accounting for rollover is that you have a maximum longest interval regardless of when it starts.

Unsigned integer rollover requires no difference in code when you handle it properly in the first place.

if ( Unsigned_Now - Unsigned_Start >= Unsigned_Interval ) {}; // ALWAYS WORKS REGARDLESS OF ROLLOVER

The only times you need "rollover code" is when you don't do the unsigned subtraction or you don't use unsigned math (or manage to klutz it up in some more convoluted way).
34  Using Arduino / Programming Questions / Re: Sketch on Mini w/328 only runs once on: April 18, 2014, 10:52:27 am
You do know that the Mini may have some differences as to pin numbers (and is there a led?) from say, the UNO?
http://arduino.cc/en/Main/ArduinoBoardMini

If you can't get this sketch to run it may be due to those very differences:
Code:
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);   
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

There could be power issues for all I know.
35  Using Arduino / Programming Questions / Re: Where am I going wrong with the no delay method? on: April 18, 2014, 10:41:29 am
Perhaps you would be better served by getting help understanding BlinkWithoutDelay first...
because it's pretty clear that you don't.
36  Using Arduino / Programming Questions / Re: Calculating slope using array issues on: April 18, 2014, 10:23:57 am
Really good coding practices don't leave the possibility of a crash.

Murphy was an optimist.
37  Using Arduino / Programming Questions / Re: How to grab responses from Serial Terminal? on: April 18, 2014, 09:16:12 am
If you hadn't posted here then I wouldn't even know about these boards yet.
38  Using Arduino / Programming Questions / Re: How Can I Serial print a sensor value each minute with out delay. on: April 18, 2014, 09:14:14 am
And to help you with future coding, maybe check out all the sections in the link below that have Operator in the name.
http://arduino.cc/en/Reference/HomePage

There's patterns to them as well as differences but they're all very useful.
39  Using Arduino / Programming Questions / Re: Calculating slope using array issues on: April 18, 2014, 09:02:42 am
To fix this, you can cast either the numerator or the denominator of the fraction as float, like this:
Code:
 float slope = (float)(readings[1]-readings[0])/(readings[3]-readings[2]);
A purist might cast both as float.

Excellent guys thank you very much for the help, it's now giving me the accuracy I was looking for. Appreciate the other feedback too. The serial print is showing the correct number but if readings are equal to zero then 'nan' or 'inf' are printed, I take it this is due to me not dealing with the issue of zero value reading as you guys mentioned. I've tried to figure it out but I'm not having much joy so maybe one of you guys could help with this?

Thanks

That is going to give you a float of the finished integer operation inside the parens.
1/5 would give 0.0 not 0.2.
You need to divide float by float not int by int.

As noted above, you need to check for divide by 0 and perhaps return a very large value for slope.
40  Using Arduino / Programming Questions / Re: How Can I Serial print a sensor value each minute with out delay. on: April 18, 2014, 12:29:12 am
Code:
 if(currentMillis - previousMillis == interval) {

This is an error waiting to happen. Maybe not in this code on this Arduino but keep using that and you'll see.

What error? Well, what happens if the exact milli where that is true is missed for any reason? That error.
41  Using Arduino / Programming Questions / Re: How to grab responses from Serial Terminal? on: April 18, 2014, 12:25:05 am
It really helps to tell up front about hardware, especially when you're using a non-standard board.
I looked up the BLUNO and it appears that there is no USB to PC on it, that the radio uses Serial instead.

I see a switch to go between AT commands and Normal Serial and scratch my head over that.
That board has its own peculiarties. I'm sure the reasons are good but those have to be understood anyway.
42  Using Arduino / Programming Questions / Re: Calculating slope using array issues on: April 18, 2014, 12:02:43 am
Code:
float slope = (readings[1]-readings[0])/(readings[3]-readings[2]);

The readings[] values are all stored as ints and unless you tell the compiler to use them differently the math done on the right hand side of the = will be done as ints. You tell the compiler how by using a cast and remember that inside of parens is a little domain where casts outside only get applied after being operated on.

Code:
int A = 1;
int B = 5;
Serial.println( A/B ); // prints 0

float C;
C = (float) A / (float) B; // C now == 0.2 or very close, floats are "funny" that way.

(float) above is the cast. Verb of cast is casting. "Casting" is short for "type casting".

Mixing data types without specifying how they are to interact is the cause of lots of hair loss and not just for newbs.
43  Using Arduino / Programming Questions / Re: How Can I Serial print a sensor value each minute with out delay. on: April 17, 2014, 11:39:05 pm

the = is what i believe is was missing right before the interval


Of course! How could anybody have missed that? What "="?

Perhaps it was your detailed and specific questions that threw me?
44  Using Arduino / Project Guidance / Re: Inconsistent values with Bluetooth and Serial.Read on: April 17, 2014, 09:07:00 pm
This is suppose to be master/slave and the led flashes different rates. It sees the PC module and goes slave but that's where I haven't got the PC end right yet. Just now I don't remember the steps I have taken but there's a dinkus I did try to set a COM channel up in before I realized I need to do a search and find a tutorial.
I'll get there.
I figured it'd be fun to BT to a tablet or netbook as am Arduino I/O terminal. Haven't got one of those yet either.
45  Using Arduino / Project Guidance / Re: Inconsistent values with Bluetooth and Serial.Read on: April 17, 2014, 05:24:18 pm
I have a BT module too, but LCSOFT's and a PC USB BT plug that I have decided to wait until I learn more to mess with again. I need to conquer more learning curve than I'm ready just yet. The PC Windows XT end looks to be the harder part of the equation but when I'm ready I'll walk that road.

I suggest that you do run both Arduinos connected to the PC at the same time. You can run two IDE's and serial monitors, start each separately and set the COM on each then make sure that when you switch the COM doesn't change -- get that real sure.
Each module can run the same code.
Each would have Serial to the PC and SoftwareSerial to the BT, the same code as if you used wire connection.
Each code would just read from whatever serial is available and echo it out the other.
What you type in through one Serial Monitor should appear in the other, I've done this to test wired serial.

Here is the SerialSoftware example from my IDE File->Examples->(etc)
You would need to change your wiring and fire up 2 terminals/IDE's & Serial Monitors, maybe the baud rates.

Code:
/*
  Software serial multple serial test
 
 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.
 
 The circuit:
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)
 
 Note:
 Not all pins on the Mega and Mega 2560 support change interrupts,
 so only the following can be used for RX:
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
 
 Not all pins on the Leonardo support change interrupts,
 so only the following can be used for RX:
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
 
 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example
 
 This example code is in the public domain.
 
 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}
Pages: 1 2 [3] 4 5 ... 304