Hi, I'm trying to create a code that will generate pulses derived from speed from the GPS module. I have Arduino uno and GPS module, everything is functional, speed is loading into variable _speed. I need a timer whose frequency will be controlled by the variable _speed, output frequency in the range of 2 to 220 Hz. Can you help me, please? Thank you. I am sorry for my English. Vitek
A not important question is: What will those 2 - 220 Hz signals go to, what will they do?
What is the range of the speed? Min, max.? What dutycycle do You want the pulses to have?
They will transmit speed to the ship's system. Speed 1 to 100 km.
So 2 Hz will show up as 1 km/h and 220 Hz shows up as 100 km/h.
Using integers You just use the built in map-function in IDE, pulse_timing = map(variable_speed, 1, 100, 500, 5).
Link to this: map() - Arduino Reference
2 Hz gives a puls every 500 1mS. 200 Hz gives a pulse every 5 mS. Pulse length at Your desire.
Thanks, good idea. But what next? The loop takes about 1 ms. Sorry, I'm a beginner.
What is the pulse width needed for the pulse to properly be accepted by the receiving device?
It is not essential, preferably 50:50
What does the specificasions say? What is the minimum pulse width? The shorter possible pulse the better accurazy of the approach I'm thinking of.
1 ms is sufficient
Good. Thanks!
Please attache Your best code soo faar. Then I can see how we can proceed.
Okay, how do I get home, I'll attach. During two days.
Fine. You are wellcome then. I don't want to make guesses and give You more headace by sending You confusing code suggestions.
Hi, I attach the code. Thank you
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 3, TXPin = 2;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
float variable_speed;
void setup()
{
Serial.begin(115200);
//set pins as outputs
pinMode(13, OUTPUT);
ss.begin(GPSBaud);
}
void loop()
{
// Dispatch incoming characters
while (ss.available() > 0) gps.encode(ss.read());
if (gps.speed.isUpdated())
{
Serial.print(F(" m/s="));
Serial.print(gps.speed.mps());
Serial.print(F(" km/h="));
Serial.println(gps.speed.kmph());
variable_speed = (gps.speed.kmph());
if (variable_speed < 1) variable_speed = 0;
Serial.print(F(" no on-site migration km/h="));
Serial.println(variable_speed,2);
}
else if (gps.satellites.isUpdated())
{
Serial.print(F(" Number of satellites "));
Serial.println(gps.satellites.value());
Serial.println(F(""));
}
}
@KZVi
You didn't see #9?
I'm sorry I do not understand you...
Will this help You?
void loop()
{
// Dispatch incoming characters
while (ss.available() > 0) gps.encode(ss.read());
if (gps.speed.isUpdated())
{
Serial.print(F(" m/s="));
Serial.print(gps.speed.mps());
Serial.print(F(" km/h="));
Serial.println(gps.speed.kmph());
variable_speed = (gps.speed.kmph());
if (variable_speed < 1) variable_speed = 0;
Serial.print(F(" no on-site migration km/h="));
Serial.println(variable_speed,2);
Start_pulse(pulse_timing = map(variable_speed, 0, 100, 500, 5). );// Start the pulse
}
Then make code for the turn off of the pulse at the end of loop. Watcing millis(), or micros() will be the key.
Well thank you
It's late here and Your real time dependant code calls for some thinking. Your while (ss.available() > 0) gps.encode(ss.read());
makes me hesitate. How much time might be spent there? Starting the pulse and waiting for the time to cut it off depends on the time spent in "while" next times. Maybe that "while" should be inhibited durint the time that the pulse is going on. Do some testing a more thinking.
Come back if You need!