To whom it may concern:
I'll start with a little detail of the system. I am working on using an RFID system to read in an RFID tag and then move a motor if the tag is the same as a stored tag. I can run the system using an Arduino Uno with the following code:
#include <SoftwareSerial.h>
SoftwareSerial gtSerial(0, 1);
//Variables
const int serialPin = 0;
const int pinRFID = 8;
const int pinL = 10;
const int pinU = 9;
const int locked = 0;
const int unlocked = 1;
char tag1[12];
char incomingByte = 1;
int index = 0;
int sts = 1; //this is the status of the mechansim. 0 = locked, 1 = unlocked
void setup() {
pinMode(pinRFID, OUTPUT);
pinMode(serialPin, INPUT);
Serial.begin(2400);
gtSerial.begin(2400);
//set up tags;
tag1[0] = '\n'; //line feed
tag1[1] = '4';
tag1[2] = '6';
tag1[3] = '0';
tag1[4] = '0';
tag1[5] = '3';
tag1[6] = '8';
tag1[7] = '9';
tag1[8] = '8';
tag1[9] = 'E';
tag1[10] = '5';
tag1[11] = '\r'; //carriage return
lock();
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(pinRFID, LOW);
delay(500);
index = 0;
if(gtSerial.available()==0){
lock();
}
if (gtSerial.available()>0){
while(index < 12) {
//read incoming byte:
incomingByte = gtSerial.read();
//print it
Serial.print("Position ");
Serial.print(index);
Serial.print(" is: ");
Serial.print(incomingByte);
Serial.print('\n');
delay(10);
if(incomingByte != tag1[index]){
lock();
break;
}
if(index == 11){
unlock();
}
index++;
}
delay(500);
}
Serial.print('\n');
Serial.print("I'm done");
Serial.print('\n');
digitalWrite(pinRFID, HIGH);
delay(500);
}
//Additional functions
void lock(){
//lock the gun if not already locked
Serial.print("Hit lock function");
Serial.print('\n');
if(sts == locked){
Serial.print("I'm already locked.");
Serial.print('\n');
return;
}
else if(sts == unlocked){
//lcok
Serial.print("Did the locking.");
Serial.print('\n');
analogWrite(pinL, 255); //set pin L to 5V (high)
analogWrite(pinU, 0); //set pin U to 0V (low)
delay(1000);
analogWrite(pinL, 0);
sts = locked;
return;
}
}
void unlock(){
//unlock the gun if not already unlocked
Serial.print("Hit unlock function");
Serial.print('\n');
if(sts == unlocked){
Serial.print("Already unlocked.");
Serial.print('\n');
return;
}
else if(sts == locked){
//unlock
Serial.print("Did the unlocking.");
Serial.print('\n');
analogWrite(pinU, 255); //set pin U to 5V (high)
analogWrite(pinL, 0); //set pin L to 0V (low)
delay(1000);
analogWrite(pinU, 0);
sts = unlocked;
return;
}
}
However, the system is such that I want to program the code to an ATtiny84 microcontroler (due to size limitations). I have seen (and followed) the directions on sites such as the following to send the code to the microcontroler:
The problem that I have is that I cannot get the microcontroler to run with the code. Here is the code that I tried to use with the microcontroler:
#include <SoftwareSerial.h>
//Variables
const int serialPin = 6;
const int pinRFID = 5;
const int pinL = 7;
const int pinU = 8;
const int locked = 0;
const int unlocked = 1;
char tag1[12];
char incomingByte = 1;
int index = 0;
int sts = 1; //this is the status of the mechansim. 0 = locked, 1 = unlocked
SoftwareSerial gtSerial(serialPin, 1);
void setup() {
pinMode(pinRFID, OUTPUT);
pinMode(serialPin, INPUT);
Serial.begin(2400);
gtSerial.begin(2400);
//set up tags;
tag1[0] = '\n'; //line feed
tag1[1] = '4';
tag1[2] = '6';
tag1[3] = '0';
tag1[4] = '0';
tag1[5] = '3';
tag1[6] = '8';
tag1[7] = '9';
tag1[8] = '8';
tag1[9] = 'E';
tag1[10] = '5';
tag1[11] = '\r'; //carriage return
lock();
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(pinRFID, LOW);
delay(500);
index = 0;
if(gtSerial.available()==0){
lock();
}
if (gtSerial.available()>0){
while(index < 12) {
//read incoming byte:
incomingByte = gtSerial.read();
//print it
Serial.print("Position ");
Serial.print(index);
Serial.print(" is: ");
Serial.print(incomingByte);
Serial.print('\n');
delay(10);
if(incomingByte != tag1[index]){
lock();
break;
}
if(index == 11){
unlock();
}
index++;
}
delay(500);
}
Serial.print('\n');
Serial.print("I'm done");
Serial.print('\n');
digitalWrite(pinRFID, HIGH);
delay(500);
}
//Additional functions
void lock(){
//lock the gun if not already locked
Serial.print("Hit lock function");
Serial.print('\n');
if(sts == locked){
Serial.print("I'm already locked.");
Serial.print('\n');
return;
}
else if(sts == unlocked){
//lcok
Serial.print("Did the locking.");
Serial.print('\n');
analogWrite(pinL, 255); //set pin L to 5V (high)
analogWrite(pinU, 0); //set pin U to 0V (low)
delay(1000);
analogWrite(pinL, 0);
sts = locked;
return;
}
}
void unlock(){
//unlock the gun if not already unlocked
Serial.print("Hit unlock function");
Serial.print('\n');
if(sts == unlocked){
Serial.print("Already unlocked.");
Serial.print('\n');
return;
}
else if(sts == locked){
//unlock
Serial.print("Did the unlocking.");
Serial.print('\n');
analogWrite(pinU, 255); //set pin U to 5V (high)
analogWrite(pinL, 0); //set pin L to 0V (low)
delay(1000);
analogWrite(pinU, 0);
sts = unlocked;
return;
}
}
As far as I know, the only real difference between the two codes is the pins that I am calling in the functions. This brings me to the question that I have: am I calling the correct pins? or am I fundamentally trying to use the ATtiny84 for something that it can't do?
I don't know if this will be super helpful, but here is the data sheet for the ATtiny84:
Please let me know if there is anything I can do to help with the process of debugging.
Thanks,
Zachary Biegler