Hello there, so for a school project I'm making tracker device using the ATtiny85. It uses the NEO6m GPS module to gather the coördinates and sends them via 1 software serial to the tiny. The tiny should then sends the coördinates (using the same software serial) to the serial monitor but this is not the case. I have put the same software on the Arduino UNO and it worked perfect, but the switch to the ATtiny does not seem to work.
here is the code that i'm using:
[ code ]
#include <SoftwareSerial.h>
#include <TinyGPS.h>
int state = 0;
const int pin = 4;
float gpslat, gpslon;
TinyGPS gps;
SoftwareSerial sgps(2, 3); //3=Tx 2=Rx
void setup()
{
sgps.begin(9600);
sgps.print("GPS searching signal...");
}
void loop()
{
sgps.listen();
while (sgps.available())
{
int c = sgps.read();
if (gps.encode(c))
{
gps.f_get_position(&gpslat, &gpslon);
}
}
if (digitalRead(pin) == HIGH && state == 0) {
sgps.listen();
sgps.print("\r");
delay(1000);
sgps.print("AT+CMGF=1\r");
delay(1000);
/*Replace XXXXXXXXXX to 10 digit mobile number &
ZZ to 2 digit country code*/
sgps.print("AT+CMGS=\"+32479317685\"\r");
delay(1000);
sgps.println("Position of your vehicle."); /
sgps.print("Latitude: ");
sgps.println(gpslat, 6);
sgps.print("Longitude: ");
sgps.println(gpslon, 6);
delay(1000);
sgps.write(0x1A);
delay(1000);
state = 1;
}
if (digitalRead(pin) == LOW) {
state = 0;
}
}
[ /code ]
Thanks in advance for taking the time to help!
comm's between attiny and pc is done over a serial-to-usb converter (ie ftdi), ftdi serial comp port on the pc is used for the serial monitor connection
attiny TX is connected from PB3 to the ftdi RX pin
GND between attiny and ftdi is connected together
GPS TX is connected to attiny PB2
GPS GND is connected to attiny GND
baud rate of attiny is set same on ftdi properties, and on serial monitor
Have you checked you are uploading ok to the 85 ( tried a simple sketch ) .
Not mixed up physical pins with Arduino I/o pin number ?
Have you set the clock speed on the tiny correctly - you need to check the processor frequency you have set - you can different baud rates depending on how this is set ( check with a simple “hello world “ example .
Does your digital input have a pull down resistor on it ?
How have you wired the software serial TX pin on the ATtiny85 so that it would be received by the serial monitor? If the answer is nothing then there is your problem.
Which ATTiny core are you using? I think the most often used one around here is Spence Konde's:
This one has a built-in software serial class called "Serial", so you wouldn't need a SoftwareSerial library.
Please mention what your fuse settings are, and in particular if you have CKDIV8 and what clock speed you are specifying in the compile.
Can you explain why you are sending what look like GPS commands: 'sgps.print("AT+CMGF=1\r");' and debugging output 'sgps.print("Latitude: ");' to the same serial interface? Is this program meant to work with the actual GPS or just print some things so you can see that it's working?
Yes, I have uploaded the "hello world" with a Baudrate of 19200, the clock speed set to 8MHz and I got great results. And no it does not have a pull down resistor.
Yes, I'm already using the SpenceKonde core and working with 8MHz clock speed. The commands you are reffering to are for sending the coördinates to a gsm number but this is not relevant yet because I'm not able to recieve and print the coördinates. It does not really make a difference I suppose. 0xE2 0xDF 0xFF 0x3F these are the fuse settings I'm using.
I have managed to get an output on the serial monitor but there is still a problem that keeps reoccuring. The problem is that the Tiny just skips the first few lines of code.
example:
void setup()
{
OSCCAL = 70 ;
sgps.begin(9600); // De GPS-module wordt gestart op een baudrate van 9600
delay(1000);
sgps.print("GPS searching signal...");
delay(1000);
}
void loop()
{
sgps.listen(); // Gps probeerd contact te krijgen met sattelietsignalen
while (sgps.available())
{
int c = sgps.read(); // De gps heeft contact gemaakt met sattelietsignalen
if (gps.encode(c))
{
gps.f_get_position(&gpslat, &gpslon); // De gps verkrijgt de latitude en longitude van de sattelietsignalen
}
}
Here is doesn't print the "GPS searching signal...", it also doesnt do the first lines of the loop where it checks the GPS for a fix. So when I press the button to send the ouput to the serial monitor it sends:
"
AT+CMGF=1
AT+CMGS="+32479317685"
Position of your vehicle.
Latitude: 0.000000
Longitude: 0.000000
"
ps: dont mind the dutch commentary in the code