SoftwareSerial with ATTiny84 using ATtiny library

• Upload the modified sketch (don't forget to remove the auto-reset disable capacitor)

Is that the on between reset and ground? I did that and no change, still get the error:

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

hilukasz:
Is that the on between reset and ground?

Yes.

I did that and no change, still get the error:

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

No change? Earlier you reported that nothing was being output to the Serial Monitor. Were error messages being output?

definitely a change, it now says --- Knock-Bang fault: 11 --- instead of nothing. Of course I should clarify, it did indicate the monitor was starting and stopping.

Edit: trimmed the unnecessary quote.

The receive errors are listed here...

The one of interest is...
fault_timeout_knock = 0x11

The receiver (your Uno) is expecting a low pulse of a certain duration (a "knock"). The pulse is too short to be a knock.

The problem could be caused by the target running at 1 MHz with code built for a processor running at 8 MHz. Which "board" do you have selected? Have you used "burn bootloader" to change the fuses?

The problem could be caused by the target running at 1 MHz with code built for a processor running at 8 MHz.

If it is of any help, I just tried a Attiny85 running at 1MHZ and selected board Attiny85 @ 8MHZ and got:

--- Knock-Bang fault: 11 ---

With the same target and selcting board Attiny85 @ 1MHZ it works as expected (Output to the serial monitor looks as it should)

Erni:

The problem could be caused by the target running at 1 MHz with code built for a processor running at 8 MHz.

If it is of any help, I just tried a Attiny85 running at 1MHZ and selected board Attiny85 @ 8MHZ and got:

--- Knock-Bang fault: 11 ---

With the same target and selcting board Attiny85 @ 1MHZ it works as expected (Output to the serial monitor looks as it should)

yeah, I just did this too. It makes sense since the frequency is 8 times faster, would make the signal shorter. I was under impression serial monitor needed to be 8Mhz like normal, but this seems to run differently.

It works perfect now! thanks guys.

I have it in still and it seems to be working fine. should I leave it? I honestly don't know what it does. I was under impression it just resets arduino so that it can program the attiny, but what that really means I have no idea.

I have it in still and it seems to be working fine. should I leave it?

As long as you use your Arduino as programmer, the capacitor between reset and ground should be connected.
It is there tp prevent your Arduino to reset and then starting the bootloader, instead of talking to the ArduinoISP.

For those using TinyISP with ATTinyx4 etc (specifically i use 84A_PU) and TinyDebugSerial at <=8Mhz

I found that on a new vanilla install (for windows 7 64) of Arduino IDE 1.0.3 (downloaded today 8/feb/2013) you should change the
define for the debug register and bit (see 2 lines below 'Use MISO as TX').

#elif defined( AVR_ATtinyX4 )

#if F_CPU <= 8000000L
// port B bit 0 (PB0)
//#define TINY_DEBUG_SERIAL_REGISTER 0x18 <<<<original settings
//#define TINY_DEBUG_SERIAL_BIT 0 <<<original settings
//use MISO as TX back to host, i.e Port A 5 (PA5)
#define TINY_DEBUG_SERIAL_REGISTER 0x1B
#define TINY_DEBUG_SERIAL_BIT 5
#else
// port A bit 0 (PA0)
#define TINY_DEBUG_SERIAL_REGISTER 0x1B
#define TINY_DEBUG_SERIAL_BIT 0
#endif

I am very new to all this (1 week in) so I hope the above is helpful, please reply if this info is erroneous and I'll correct.

PS: Thx very much for TinyISP, makes using 84/85's almost pleasurable :wink:

Kind Regards

did that file get revered maybe? I formatted and had to download it again and that file seems to be missing again.

Build options now go in the _TinyISP_BuildOptions.h file. It should be the last tab if you have the sketch loaded in the Arduino IDE.

Other than the copyright notice, I will never put anything in that file. It's sole purpose is for you to specify build-time settings.

ah, must have ended up messing with that one instead last time. wrote it down this time :slight_smile:

Ok the basic examples seem to work fine, for most part..

sketch:

#define KNOCK_BANG 1
#include <TinyDebugKnockBang.h>
 
#ifdef KNOCK_BANG
#define Serial Debug
#endif
int a;
void setup() {
    Serial.begin( 9600 );
        a = 1;
}
 
void loop() {
    delay(1000);
    Serial.println("hello world"); // debug output
    Serial.println(a); // debug output
    a++;
}

this is the output, though for some reason I always have to send "!" twice for it to work:

ÿ //this shows up without me typing "!"
--- Monitor starting ---

--- Knock-Bang fault: 11 ---
hello world
6
hello world
7
hello world
8
hello world
9

ok great, now I try a more complex one and everything falls apart. for some reason it is storing program from last upload...? I do stop the serial monitor before uploading, not sure if that matters.

the sketch:

#include <CapacitiveSensor.h>
#include <RunningMedian.h>
#define KNOCK_BANG 1
#include <TinyDebugKnockBang.h>
#ifdef KNOCK_BANG
#define Serial Debug
#endif

CapacitiveSensor cs_4_2 = CapacitiveSensor(1,0);        // 10 megohm resistor between pins 1 & 0, pin 0 is sensor pin, add wire, foil
const int sampleAmount = 5; 
long runningAverage[sampleAmount];
boolean toggleLED;
int var;
    
boolean handIsPresent;    
void setup(){
   Serial.begin(9600);
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   pinMode(2, OUTPUT);
   pinMode(1, OUTPUT);
   pinMode(0, INPUT);
   var = 0;
   handIsPresent = false;  
}
void loop(){ 
   //findCurrentHighestAverage
   checkIfHandIsPresent();
   if(handIsPresent){
     toggleTheLED();
   }
   delay(10);
   Serial.print("test");
}

void toggleTheLED(){
       if(toggleLED == 0){
         digitalWrite(2, LOW);
         toggleLED = 1;
         //delay(2000);
         return;
       } else if(toggleLED == 1) { 
          digitalWrite(2, HIGH);
          toggleLED = 0; 
          //delay(2000);
       }
}

////////////////
// Check if hand is present
//--------------

int lastReading;

void checkIfHandIsPresent(){
  const int threshold = 300;
  int currentReading = getAverage();

  Serial.print(currentReading-lastReading);
  Serial.print("\n");
  // this will always only read when 
  if((currentReading-lastReading) > threshold){ 
    handIsPresent = true;
  } else { handIsPresent = false; } 
  lastReading = currentReading;
}

////////////////
// get average reading out of X samples
//--------------
int getAverage() {
   int tempAverage = 0;
   int capacitiveAverage = 0;
   for(int i = 0; i < sampleAmount; i++){
    runningAverage[i] = cs_4_2.capacitiveSensor(30);
   } 
   // add all the samples up
   for(int i = 0; i < sampleAmount; i++){
     tempAverage = runningAverage[i] + tempAverage;
   } 
   // divide by number of samples to get average
   capacitiveAverage =  tempAverage/sampleAmount;
   //printSampleData(capacitiveAverage);
   return capacitiveAverage;
}
73
hello world
74
hello world
75
hello world
76
hello world
77
hello world
78
hello world
79

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 4 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

73
hello world
74
hello world
75
hello world
76
hello world
77
hello world
78
hello worl
--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 4 ---

this is the output, though for some reason I always have to send "!" twice for it to work:

I've had that happen a few times but typically the transition is smooth. I can't explain why you always have to send bang twice.

ÿ //this shows up without me typing "!"

I often get a bit of garbage as well. I haven't bothered to track down why.

hilukasz:
ok great, now I try a more complex one and everything falls apart. for some reason it is storing program from last upload...?

Any upload errors?

I do stop the serial monitor before uploading, not sure if that matters.

Shouldn't matter. The TinyISP sketch is coded to jump to the ISP part automatically.

just the standard:

Binary sketch size: 3,044 bytes (of a 8,192 byte maximum)
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

get this with all attiny uploads though.

hilukasz
One thing to try:
Ensure that the MISO connection wire is as short (and fat) as possible:

(reply #74)

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

This is jusr a warning, just ignore it.

Erni:
hilukasz
One thing to try:
Ensure that the MISO connection wire is as short (and fat) as possible:

SoftwareSerial with ATTiny84 using ATtiny library - #75 by Coding_Badly - Microcontrollers - Arduino Forum
(reply #74)

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

This is jusr a warning, just ignore it.

thanks for suggestion. However, one I have now is very short and as large gauge as will fit in the pins :frowning:

I'm wondering if it is something in my code conflicting with this type of serial read? It's strange that a simple example would work, and not my more complex one.

also as I am learning to get all this right (hopefully eventually :slight_smile: I am trying to document it for the UNO as I go here: http://hellowoo.com/hardware/serial-monitor-with-attiny85-and-arduino/

Hmm, you are using the MOSI and MISO lines (0 and 1) as you sense pins.

CapacitiveSensor cs_4_2 = CapacitiveSensor(1,0);

Try this instead, works for me (I think, atleast I don't get knock bang errors)

CapacitiveSensor cs_4_2 = CapacitiveSensor(1,0);

Erni:
Hmm, you are using the MOSI and MISO lines (0 and 1) as you sense pins.

CapacitiveSensor cs_4_2 = CapacitiveSensor(1,0);

Try this instead, works for me (I think, atleast I don't get knock bang errors)

CapacitiveSensor cs_4_2 = CapacitiveSensor(1,0);

oh doh! is it this line: #define KNOCK_BANG 1 because that was new on this round of sketches. I thought default was pin 3 (PCB3)? What weirds me out is this works on the first sketch I show above...? I can read the serial fine via pin 3, but its second sketch that fails.

I did try some tests to change it to #define KNOCK_BANG 3 and it seems like the same problem.

Ohh, my copy/paste technique was bad.

What I really meant was; Try moving the sense pins to PB3 and PB4.

CapacitiveSensor cs_4_2 = CapacitiveSensor(PB3,PB4);

If you are using 0 and 1 you are interferring with MISO, which is used by KnockBang, and gives the weird results and errors.

I tried your sketch wirth this change and the output is OK.