Show Posts
Pages: [1] 2 3 ... 196
1  Using Arduino / Project Guidance / Re: Count 18 lines and pause. on: April 16, 2014, 11:48:50 pm
EDIT:
To make things simpler for you us, this has gone on long enough.

Code:
void setup()
{
  Serial.begin(9600); // should really be set to 115200, but just this is just a demonstration of how FOR loops work.
}

void loop()
{
  for( byte i = 0; i < 10; i++)
  {
    Serial.println(i); // prints 0 - 9, per line
  }
  Serial.println("End of block);
  delay(5000); // Just so it gives you time to see the results, without them flashing across the screen
}
2  Using Arduino / Project Guidance / Re: Sport Bike Cluster on: April 16, 2014, 11:41:03 pm
What about maybe using a laser trip wire and your spokes? The beam breaks, record the time then once it passes the second spoke find the difference of the two times and get your speed that way.

I have a sketch you can use to get you going, for right now it uses tactile buttons to simulate a car passing through two gates that are 35 feet away from each other. All you would need to do is substitute the buttons for the sensor (you will need to modify the code a little since your using one sensor) and change the 35 feet to the distance between the two spokes.

Code:
#define FPS_to_MPH 0.68182 // scale factor
#define DISTANCE 35.5625 // distance between the two sensors or gates.

const byte SensorOnePin = 2;
const byte SensorTwoPin = 3;

byte SensorOneState;
byte SensorTwoState;
float Speed = 0, MPH = 0, tmp = 0;
boolean GotSecondSensor = false;
unsigned long SensorOne_timer = 0, SensorTwo_timer = 0;

void setup()
{
  Serial.begin(115200);
  pinMode(SensorOnePin, INPUT);
  pinMode(SensorTwoPin, INPUT);
}

void loop()
{
  // This is using normal buttons to detect car passing through one gate to another,
  // this can be changed to use US sensors to replace the buttons. That part you will 
  // need to write yourself.
 
  SensorOneState = digitalRead(SensorOnePin);
  SensorTwoState = digitalRead(SensorTwoPin);

  if(SensorOneState && GotSecondSensor == false)  // car drives through first gate "sensor"
  {
    SensorOne_timer = millis(); // record time
    GotSecondSensor = true; // lockout this IF statement and unlock the next IF statement
  }
 
  if(SensorTwoState && GotSecondSensor == true)
  {
    SensorTwo_timer = millis(); //record the time the car reaches the second gate
    Speed = GetSpeed(SensorOne_timer, SensorTwo_timer, DISTANCE); // send the times and the distance into the function.
    Serial.print("MPH: ");
    Serial.println(Speed);
    GotSecondSensor = false; // unlock first IF statement and lockout this IF statement.
  }
}

float GetSpeed(unsigned long T1, unsigned long T2, float distance)
{
  MPH = distance * (FPS_to_MPH); // "(FPS_to_MPH)" -> conversion factor, feet per second to miles per hour
  tmp = (T2 - T1)/1000.00; // since the time we are using is in milliseconds, we need to convert milliseconds to seconds
  Serial.print("Time (seconds): ");
  Serial.println(tmp);
  return (MPH / tmp); //return the speed of the car in MPH
}
3  Using Arduino / Project Guidance / Re: Inconsistent values with Bluetooth and Serial.Read on: April 16, 2014, 11:16:50 pm
Try these.

Master:
Code:
void setup()
{
  Serial.begin(9600);
  delay(1);
  Serial.println("Transmitting");
}

void loop()
{
  Serial.print('H');
  delay(1000);
  Serial.print('L');
  delay(1000);
}

Slave: Keep in mind you will need to use Software serial if you want to use the Serial monitor, to see the received char.
Code:
char val; // variable to receive data from the serial port
int ledpin = 13; // LED connected to pin 13 (on-board LED)

void setup() {
  pinMode(ledpin, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
  Serial.begin(9600);       // start serial communication at 115200bps, must match the transmitting side
  delay(1);               // 1 millisecond delay between starting the serial communication and sending out a message
  Serial.println("Receiving");    
}

void loop()
{
  if( Serial.available() > 0)       //See if data is available to read
  {
    val = Serial.read();
    Serial.println(val);

    if( val == 'H' || val == 'h' )               // if 'H' was received
    {
      digitalWrite(ledpin, HIGH);  // turn ON the LED
    }
    if( val == 'L' || val == 'l' )
    {
      digitalWrite(ledpin, LOW);   // otherwise turn it OFF
    }
  }
}

Make sure the Serial monitor is set to 9600, otherwise you will see garbage in the terminal.

EDIT:
On second thought, they might need to be set to 9600, as per the default baud rate. I changed them.
4  Development / Other Software Development / Re: New TFT Extension Library on: April 16, 2014, 04:51:13 pm
I can make the rounded_square, maybe the moon, smiley faces, text-balloon, hourglass and music bar + notes.

The Greek, math and currency symbols would be easy to make if I could get into the original character table, but I'll try.

Do you want to hourglass to flip over?

Added:
Rounded_Square : DONE (no fill yet)
5  Using Arduino / Programming Questions / Re: Searching for info regarding the PS2X Library on: April 15, 2014, 09:23:01 pm
You would need to learn about the Bink Without Delay sketch and how it works.
6  Using Arduino / Project Guidance / Re: Inconsistent values with Bluetooth and Serial.Read on: April 15, 2014, 08:04:05 pm
Is the 3 still in double quotes, if so, you want to receive a char, so you need to send a char. Simply put, you need to use single quotes not double quotes.

Serial.print( '3' );

If you still get garbage, check your wiring. BT: Tx -> Ard: Rx and BT: Rx -> Ard: Tx
This needs to be done for both master and slave.
7  Using Arduino / Programming Questions / Re: Searching for info regarding the PS2X Library on: April 15, 2014, 07:57:45 pm
I looked over your code and compared it to mine and it seems your missing this function.
ps2x.read_gamepad(false, 0);

Add that function in your loop().
8  Using Arduino / Programming Questions / Re: Searching for info regarding the PS2X Library on: April 15, 2014, 05:27:43 pm
Quote
the values come back as expected so I doubt it is a wiring issue...
What values, the buttons?
Can you post a picture of your setup?
9  Using Arduino / Programming Questions / Re: very very important - help me on: April 15, 2014, 05:26:00 pm
You need to have the actual library in the correct place, and some photos of your wiring would be really helpful. Check out this post HERE.
10  Development / Other Software Development / Re: New TFT Extension Library on: April 15, 2014, 04:24:18 pm
I have three more functions on the way, two are already done and one i'm still working on.
The two that are done are drawArc and TouchArc.

drawArc(int cx, int cy, int radius, int start, int stop, int thickness, byte R, byte G, byte B);
Like my circle function, it needs a X/Y coordinate, a radius, and now it needs a start and stop angle, a thickness (will not exceed the radius value or below 0) and finally, a color.

TouchArc(int cx, int cy, int radius, int start, int stop, int thickness);
This function returns a percentage of where you touch the arc from right to left. 0  - 100%

And the last function is a Slider, it can either be horizontal or vertical, and it too will return the percentage of it's level.
It can be mapped to any size or thickness, and I must insist you use a stylist or something with a soft point.
11  Using Arduino / Programming Questions / Re: Searching for info regarding the PS2X Library on: April 15, 2014, 04:13:30 pm
Quote
I added the comma and it makes it much easier to read smiley-razz Is there a way I can tell it to kick the next set of values down to the next line on the serial monitor?
Yea, that was my fault, change the last one to Serial.println(Input2);

Quote
1501,1501,etc.
Is there something wrong with how I used/ setup the map function?
The joysticks work exactly like a potentiometer, so full up is 255 and full down is 0, so in between is 128, and when you map 128, that equals to ~1500. Those values should increase and decrease when you move the stick, if it doesn't then there may be a problem with the wiring or the controller itself.

How much voltage is the controller getting, 3.3 or 5V? I have a regular and a wireless controller and they only seem to work at 3.3V.
12  Using Arduino / Project Guidance / Re: Inconsistent values with Bluetooth and Serial.Read on: April 14, 2014, 11:37:06 pm
Make it Serial.print on the master side and a type char on the slave side.
13  Using Arduino / Programming Questions / Re: Searching for info regarding the PS2X Library on: April 14, 2014, 10:49:00 pm
Is the little center button pressed(red light), the one below the start and select buttons?

Quote
Input1 = map(ps2x.Analog(PSS_LY), 0, 255, 1000, 2000);
     //Signal1.writeMicroseconds(Input1);
     Serial.print (Input1);
     
      Input1 = map(ps2x.Analog(PSS_LX), 0, 255, 1000, 2000);
     // Signal2.writeMicroseconds(Input1);
      Serial.print (Input2);
      delay(1000);

You should really add a comma to separate them, like so.

Serial.print(Input1); Serial.print(", "); Serial.print(Input2); // I wrote it like this so you can see what I'm trying to do.
Output: yyyy, xxxx
14  Using Arduino / Project Guidance / Re: Wireless Switch Using Transmitters and Receivers on: April 14, 2014, 02:26:57 pm
Yes, with the Virtualwire library, it is possible to do just that.
Do you have the RF modules? If you don't the cheapest modules are these, 433MHz RF transmiter/receiver

Once you do have them, start with turning a LED on and off, then move to the relay.
15  Using Arduino / Programming Questions / Re: Trouble adapting Speed code (Reed Switch) on: April 14, 2014, 01:17:43 pm
Whoever wrote this code, did not label everything. There is a magic number here,
Quote
mph = (56.8*float(circumference))/float(timer);
which is crucial to your calculations. You can't just change the radius without knowing what each part does and what each number represents.

What is the 56.8 and how does it work with the original 13.5?
Pages: [1] 2 3 ... 196