Go Down

Topic: problems with softserial and ATtiny85 (Read 1 time) previous topic - next topic

NeX

hi all,

i am using an ATtiny to receive serial commands and respond to them by transmitting infrared commands.

what i would like to do is simulate the original remote, and one of the features of the remote is to have extra commands if the button is held down.

i made a mock up with a regular arduino and loading up hyper terminal on the computer. when i hold down a key on the computer it triggers the arduino and the device responds as if a remote with the button held down has been pointed at it. in other words it works fine

but then i ported the code to an ATtiny85 using an external 16mhz resonator (the same as the ones on the arduino pro mini) and of course i had to use Softserial but now the hold feature doesn't work

sending one serial command works perfectly, but sending serial commands repeatedly doesn't work like it did on the regular arduino



i hope all that makes sense, its a bit difficult to explain but one thing i would like to know is the possible limits of softserial compared to hardware serial

thanks guys!

PaulS

"Hi guys. I have a code problem, but I'm not going to show you any code. Please help".

Did I paraphrase that correctly?

NeX

why do people on this forum have to be so passive aggressive?

no matter how much code i post it wont answer my question: "what are the limits of software serial compared to hardware serial?"

but seeing as people don't read unless it is in a little code window, here:

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

SoftwareSerial mySerial(0, 1); // RX, TX


#define TOPBIT 0x80000000

#define NEC_HDR_MARK 9000
#define NEC_HDR_SPACE 4500
#define NEC_BIT_MARK 560
#define NEC_ONE_SPACE 1600
#define NEC_ZERO_SPACE 560
#define NEC_RPT_SPACE 2250

int inByte = 0;

void setup()
{
  DDRB  = DDRB  &~B00000100;
  PORTB = PORTB &~B00000100;
  mySerial.begin(9600);
}

void loop()
{
  while (mySerial.available() > 1) {  //removes lag, serial fills up and continues to repeat scommands even after serial input has stopped
    mySerial.read();
  }
  if (mySerial.available() > 0) {
    inByte = mySerial.read();
      switch (inByte) {
      case 99:  //c
        um_sendNEC(0xB54A9867, 32);  //Wheel Clockwise
        um_sendNEC(0xF50AFE01, 32);  //Wheel Clockwise
      break;
      case 97:  //a
        um_sendNEC(0xB54A9867, 32);  //Wheel Anticlockwise
        um_sendNEC(0xF50A7E81, 32);  //Wheel Anticlockwise
      break;
      case 98:  //b
        um_sendNEC(0xB54A9867, 32);  //Centre Button
        um_sendNEC(0xF50ABE41, 32);  //Centre Button
      break;
      case 43:  //+
        um_sendNEC(0xB54A50AF, 32);  //Vol Up
      break;
      case 45:  //-
        um_sendNEC(0xB54AD02F, 32);  //Vol Down
      break;
      case 114: //r
        um_sendNEC(0xB54A48B7, 32);  //BAND
      break;
      case 116: //t
        um_sendNEC(0xB54A30CF, 32);  //ATT
      break;
      case 100: //d
        um_sendNEC(0xB54A9867, 32);  //DISP
        um_sendNEC(0xF50AB649, 32);  //DISP
      break;
      case 115: //s
        um_sendNEC(0xB54A58A7, 32);  //SRC
      break;
      case 101: //e
        um_sendNEC(0xB54AD22D, 32);  //EQ
      break;
      case 102: //f
        um_sendNEC(0xB54A9867, 32);  //DF
        um_sendNEC(0xF50A16E9, 32);  //DF
      break;
      case 117: //u
        um_sendNEC(0xB54A02FD, 32);  //Up
      break;
      case 111: //o
        um_sendNEC(0xB54A827D, 32);  //Down
      break;
      case 108: //l
        um_sendNEC(0xB54A42BD, 32);  //Left
      break;
      case 105: //i
        um_sendNEC(0xB54AC23D, 32);  //Right
      break;
      default:
        inByte = 0;
    }
   // mySerial.write(inByte);
    inByte = 0;
  }
}

void um_sendNEC(unsigned long data, int nbits)
{
  um_mark(NEC_HDR_MARK);
  um_space(NEC_HDR_SPACE);
  for (int i = 0; i < nbits; i++) {
    if (data & TOPBIT) {
      um_mark(NEC_BIT_MARK);
      um_space(NEC_ONE_SPACE);
    }
    else {
      um_mark(NEC_BIT_MARK);
      um_space(NEC_ZERO_SPACE);
    }
    data <<= 1;
  }
  um_mark(NEC_BIT_MARK);
  um_space(0);
}


void um_mark(int time) {
  DDRB  = DDRB  | B00000100;
  delayMicroseconds(time);
}

void um_space(int time) {
  DDRB  = DDRB  &~B00000100;
  delayMicroseconds(time);
}

PaulS

Quote
why do people on this forum have to be so passive aggressive?

Who's being passive?

Code: [Select]
  while (mySerial.available() > 1) {  //removes lag, serial fills up and continues to repeat scommands even after serial input has stopped
    mySerial.read();
  }

Why? If there is more than one byte in the buffer, throw away all the data except the last byte. Perhaps the data that you want just hit the bit bucket.

Code: [Select]
      case 99:  //c
Wouldn't
Code: [Select]
      case 'c':
be easier to understand and modify (and maintain)?

Quote
what are the limits of software serial compared to hardware serial?

Software serial's interrupts can interfere with other things on the Arduino (or ATTiny). HardwareSerial's interrupts are processed much faster, so the possibility of interference is less.

NeX

thank you for the reply,

the while loop removes excess data so that only current data is being processed, if no more data is received then i don't want it to continue processing data in the buffer. but i have tried the code without this loop and still doesn't work, and this loop does work on the ATmega328 version, so i know the loop is not to blame.

thanks for the recommendation i will change my case statements to ASCII

can you be a bit more specific about what conflicts with software serial? as i said before, the atmega version works fine with hardware serial so i am assuming that the problem lies with the software serial.

Go Up