Go Down

Topic: Attempting to use ATtiny84 (Read 171 times) previous topic - next topic

jhatf

Feb 13, 2015, 05:27 pm Last Edit: Feb 13, 2015, 05:40 pm by jhatf
I previously used Arduino Uno and also tried ATMega328 as a standalone.. Now I am trying to use ATtiny84 to run my program as a standalone. However, with my code that worked for ATMega and Arduino, it is now not registering right with my ATtiny. I know they often do not go together, but I am getting a strange error that I cannot seem to find out how to fix.

In file included from /Users/hatfieldj/Documents/Arduino/libraries/jeelib-master/JeeLib.h:17,
                from EnrollVerifyCombo.ino:12:
/Users/hatfieldj/Documents/Arduino/libraries/jeelib-master/Ports.h:713: error: 'Serial' was not declared in this scope
/Users/hatfieldj/Documents/Arduino/libraries/jeelib-master/Ports.h:714: error: 'Serial' was not declared in this scope
EnrollVerifyCombo.ino: In function 'void setup()':
EnrollVerifyCombo:31: error: 'Serial' was not declared in this scope
EnrollVerifyCombo.ino: In function 'void Enroll()':
EnrollVerifyCombo:51: error: 'Serial' was not declared in this scope
EnrollVerifyCombo.ino: In function 'void loop()':
EnrollVerifyCombo:151: error: 'Serial' was not declared in this scope
EnrollVerifyCombo:160: error: 'Serial' was not declared in this scope
EnrollVerifyCombo:176: error: 'Serial' was not declared in this scope

Am I missing something? How come the serial was declared fine in ATMega from the library, but using ATtiny does not accept this?

Code: [Select]
#include <FPS_GT511C3.h>
#include <SoftwareSerial.h>
#include <Stepper.h>
#include <JeeLib.h>

uint8_t getFingerprintEnroll(uint8_t id);
ISR(WDT_vect) { Sleepy::watchdogEvent(); }

FPS_GT511C3 fps(4, 5);
Stepper myStepper(750, 9, 10, 11, 12);
int inPin1 = 9;
int inPin2 = 10;
int inPin3 = 11;
int inPin4 = 12;
int buttonPin = 7;
int ledPin = 8;    
int ledPin2 = 13;  



void setup()  
{
  Serial.begin(9600);
  myStepper.setSpeed(35);
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  Sleepy::loseSomeTime(50);
  fps.Open();
  fps.SetLED(true);    // Perhaps setting this to false will reduce mAh?
  Enroll();
}

void Enroll(){

int enrollid = 0;
bool okid = true;
while (okid == true)
{
okid = fps.CheckEnrolled(enrollid);
if (okid==true) enrollid++;
}
        {
        Serial.println(enrollid);
        if (enrollid <= 19);
        {
fps.EnrollStart(enrollid);

// enroll
Serial.print("Please press finger to Enroll #");
        digitalWrite(ledPin2, HIGH);
Serial.println(enrollid);
        if (enrollid <= 19)
        {
while(fps.IsPressFinger() == false) Sleepy::loseSomeTime(50);
bool bret = fps.CaptureFinger(true);
int iret = 0;
if (bret != false)
{
                digitalWrite(ledPin2, LOW);
              
Serial.println("Please remove finger");
                digitalWrite(ledPin, HIGH);
fps.Enroll1();
                digitalWrite(ledPin, LOW);
while(fps.IsPressFinger() == true) Sleepy::loseSomeTime(50);
Serial.println("Please press same finger again");
                digitalWrite(ledPin2, HIGH);
while(fps.IsPressFinger() == false) Sleepy::loseSomeTime(50);
bret = fps.CaptureFinger(true);
if (bret != false)
{
                        digitalWrite(ledPin2, LOW);
Serial.println("Please remove finger");
                        digitalWrite(ledPin, HIGH);
fps.Enroll2();
                        digitalWrite(ledPin, LOW);
while(fps.IsPressFinger() == true) Sleepy::loseSomeTime(50);
Serial.println("Please press same finger yet again");
                        digitalWrite(ledPin2, HIGH);
while(fps.IsPressFinger() == false) Sleepy::loseSomeTime(50);
bret = fps.CaptureFinger(true);
if (bret != false)
{
                                digitalWrite(ledPin2, LOW);
Serial.println("Please remove finger");
                                digitalWrite(ledPin, HIGH);
iret = fps.Enroll3();
                                digitalWrite(ledPin, LOW);
if (iret == 0)
{
Serial.println("Enrolling Successfull");
                                        digitalWrite(ledPin, HIGH);
                                        digitalWrite(ledPin2, HIGH);
                                        Sleepy::loseSomeTime(200);
                                        digitalWrite(ledPin, LOW);
                                        digitalWrite(ledPin2, LOW);
                                        Sleepy::loseSomeTime(200);
                                        digitalWrite(ledPin, HIGH);
                                        digitalWrite(ledPin2, HIGH);
                                       Sleepy::loseSomeTime(200);
                                        digitalWrite(ledPin, LOW);
                                        digitalWrite(ledPin2, LOW);
                                        Sleepy::loseSomeTime(200);
                                        digitalWrite(ledPin, HIGH);
                                        digitalWrite(ledPin2, HIGH);
                                        Sleepy::loseSomeTime(200);
                                        digitalWrite(ledPin, LOW);
                                        digitalWrite(ledPin2, LOW);
}  
else
{
Serial.print("Enrolling Failed with error code:");
Serial.println(iret);
}
}
else Serial.println("Sorry, unable to capture third finger");
                        digitalWrite(ledPin, LOW);
                        digitalWrite(ledPin2, LOW);
}
else Serial.println("Sorry, unable to capture second finger");
                digitalWrite(ledPin, LOW);
                digitalWrite(ledPin2, LOW);
}
else Serial.println("Sorry, unable to capture first finger");
        digitalWrite(ledPin, LOW);
        digitalWrite(ledPin2, LOW);
        }
        else{
          digitalWrite(ledPin, LOW);
          digitalWrite(ledPin2, LOW);
        }
        }
}
}
void loop(){
 
if (fps.IsPressFinger())
{
fps.CaptureFinger(false);
int id = fps.Identify1_N();
if (id <20)
{
Serial.print("Hello! Fingerprint has been verified:");
Serial.println(id);
                        myStepper.step(750);
                        Sleepy::loseSomeTime(2000);
                        myStepper.step(-750);
                        Sleepy::loseSomeTime(2000);
}
else
{
                        Serial.println("Sorry, fingerprint was not found in database");
                        digitalWrite(ledPin, HIGH);
                        Sleepy::loseSomeTime(50);
                        digitalWrite(ledPin, LOW);
                        Sleepy::loseSomeTime(50);
                        digitalWrite(ledPin, HIGH);
                        Sleepy::loseSomeTime(50);
                        digitalWrite(ledPin, LOW);
                        Sleepy::loseSomeTime(50);
                        digitalWrite(ledPin, HIGH);
                        Sleepy::loseSomeTime(50);
                        digitalWrite(ledPin, LOW);
}
}
else
{
Serial.println("Please press finger");
}
Sleepy::loseSomeTime(1000);
 
}


I realize it may not be the cleanest code, but it works in ATMega. What am I missing to get it to upload to ATtiny84 through Arduino Uno? I realize I will have to add/change pins around to get it to run successfully through an ATtiny. But what is wrong with Serial?

EDIT: I do use Arduino 1.0.6 for all of this. If this changes anything.

DrAzzy

That is correct indeed!

Serial is defined on the Uno and Mega because those devices have a hardware UART.

The Tiny84 does not have hardware serial, so there is no Serial.

You need to either remove the usage of Serial (if the use is not integral to the functioning of the sketch, like debug code), or replace it with SoftwareSerial (if it is). Note that there are several variations of SoftwareSerial, each of which has different limitations (none of them work exactly like a hardware serial)
Tiny841 Core: http://drazzy.com/e/tiny851.shtml
Please don't PM me questions or responses to my posts. I am unlikely to see or read them.

jhatf

Now I deleted all the Serial lines from my code just to see what would happen, and this is what I got. Does this mean I should follow the SoftwareSerial route? And how would I go about using that to get it running?

Code: [Select]
#include "FPS_GT511C3.h"
#include <Stepper.h>
#include <JeeLib.h>
// Hardware setup - FPS connected to:
//   digital pin 4(arduino rx, fps tx)
//   digital pin 5(arduino tx - 560ohm resistor - fps tx - 1000ohm resistor - ground)
// this voltage divider brings the 5v tx line down to about 3.2v so we dont fry our fps
ISR(WDT_vect) { Sleepy::watchdogEvent(); }

FPS_GT511C3 fps(4, 5);
Stepper myStepper(255, 9, 10, 11, 12);
int inPin1 = 9;
int inPin2 = 10;
int inPin3 = 11;
int inPin4 = 12;



void setup()
{
        myStepper.setSpeed(20);
delay(100);
fps.Open();
fps.SetLED(true);
}

void loop()
{

// Identify fingerprint test
if (fps.IsPressFinger())
{
fps.CaptureFinger(false);
int id = fps.Identify1_N();
if (id <200)
{

                        myStepper.step(255);
                        delay(3000);
                        myStepper.step(-255);
}
else
{

}
}
else
{

}
delay(100);

}


Errors from this:

In file included from FPS_IDFinger.ino:1:
/Arduino/libraries/NewFingerScanner/FPS_GT511C3.h:13:28: error: SoftwareSerial.h: No such file or directory
In file included from FPS_IDFinger.ino:1:
/Documents/Arduino/libraries/NewFingerScanner/FPS_GT511C3.h:343: error: 'SoftwareSerial' does not name a type
In file included from /Arduino/libraries/jeelib-master/JeeLib.h:17,
                 from FPS_IDFinger.ino:3:
/Arduino/libraries/jeelib-master/Ports.h:713: error: 'Serial' was not declared in this scope
/Arduino/libraries/jeelib-master/Ports.h:714: error: 'Serial' was not declared in this scope

DrAzzy

#3
Feb 13, 2015, 07:05 pm Last Edit: Feb 13, 2015, 07:06 pm by DrAzzy
Including software serial would be a good start.

There are unfortunately two calls to Serial in jeelib that you'll need to fix too

http://arduino.cc/en/Reference/SoftwareSerial

Study that page, and how the libraries use Serial, to make sure that the limitations of SoftwareSerial won't be a problem.
Tiny841 Core: http://drazzy.com/e/tiny851.shtml
Please don't PM me questions or responses to my posts. I am unlikely to see or read them.

jhatf

I previously had SoftwareSerial included, still had the same errors with JeeLib. What two calls to Serial in jee lib do I need to fix? I do believe I don't need the Serials, as I want the ATtiny84 to work as a stand alone with my project with no connections to the computer. However, I still want to keep the JeeLib for the purpose of loseSomeTime.

nicoverduin

While developing, SoftwareSerial can be handy. What I usually do is at the top of the program:
Code: [Select]

#define DEBUG


And in my code:
Code: [Select]

#ifdef DEBUG
  mySerial.print(......
#endif


Commenting out the top line will hide all mySerial code from the compiler and is thus not included.
Met vriendelijke groet / kindest regards
Nico Verduin
www.verelec.nl
Do not PM me for personal consultancy unless you are willing to pay for it.

DrAzzy

#6
Feb 13, 2015, 08:17 pm Last Edit: Feb 13, 2015, 08:20 pm by DrAzzy
See, I don't know what jeelib does - all I can see is that you're getting errors from references to Serial there. And you'll need to find and remove them.

I also don't know whether, in your project, you're communicating with those devices over serial or not. If you're not communicating with any of the attached devices over serial, then you don't need software serial at all, and can just go commenting out all the uses of Serial. I assumed that you were using the serial to talk to something you had connected to it. If not, you can just ditch all the Serial.print... statements and not use software serial at all.
Tiny841 Core: http://drazzy.com/e/tiny851.shtml
Please don't PM me questions or responses to my posts. I am unlikely to see or read them.

jhatf

I will try that Nicoverduin! As for DrAzzy, I earlier used Serial.print for when I was using Arduino Uno to run this and I would use Serial Monitor as a helper. However, I don't use it anymore, but even when I take it out of my code, I still get the errors from JeeLib and Serial. I'm not quite sure why ATtiny does not approve, because it works perfectly fine with ATMega328/Arduino Uno. What gets even crazier, is if I delete all of the JeeLib and Serial parts of my code and try to verify it.. It than gives me errors saying SoftwareSerial does not name a type in my other libraries such as my FPS. What is this about??

DrAzzy

#8
Feb 13, 2015, 10:22 pm Last Edit: Feb 13, 2015, 10:24 pm by DrAzzy
The reason the ATTiny complains about attempts to use Serial is that the tiny DOES NOT HAVE A SERIAL PORT. If you put Serial.whatever() into a sketch on a Tiny84, you are trying to interact with a peripheral that DOES NOT EXIST. The compiler prevents you from doing this. This behavior is 100% correct and expected.


The errors from FPS library are due to SoftwareSerial not being a direct replacement for Serial. I assume you went through and tried to change the Serial to SoftwareSerial in there. I'd go change it back, and instead comment out those lines - since you say the serial was just for debugging.

The errors from jeelib is because that library contains calls to Serial. Go through that library, find the calls to serial, and comment them out.
Tiny841 Core: http://drazzy.com/e/tiny851.shtml
Please don't PM me questions or responses to my posts. I am unlikely to see or read them.

Coding Badly

The Tiny84 does not have hardware serial, so there is no Serial.
https://code.google.com/p/arduino-tiny/

...includes a write-only Serial very useful for debugging.


DrAzzy

#10
Feb 13, 2015, 11:57 pm Last Edit: Feb 13, 2015, 11:58 pm by DrAzzy
https://code.google.com/p/arduino-tiny/

...includes a write-only Serial very useful for debugging.


Interesting, that *is* useful. Built-in write only software serial right in the core...
Tiny841 Core: http://drazzy.com/e/tiny851.shtml
Please don't PM me questions or responses to my posts. I am unlikely to see or read them.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy