Pages: [1]   Go Down
Author Topic: ATtiny Capacitive Sensing and Sound  (Read 113 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 1
I'm a maker, producer & educator, spanning creative technology, crafting & pervasive gaming. I run a creative technology education company called Codasign & I'm also working for The Open University on a project exploring eTextiles and visual impairment.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

I'm trying to get a sketch working on an ATtiny85-20PU which will allow me to do capacitive sensing with the chip whilst also changing  a sound output. The sketch I wanted to use was this one, an amended version of Paul Badger's (there is an h file in the folder too):

#include <CapacitiveSensor.h>

CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
int speakerPin = 12;
int pitch = 0;
int ledPin = 13;

void setup()                   

void loop()                   
    long start = millis();
    long total1 =  cs_4_2.capacitiveSensor(100);

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing

    Serial.println(total1);                  // print sensor output 1

    delay(10);    // arbitrary delay to limit data to serial port
  pitch = total1/26;
  tone(speakerPin, pitch);
  analogWrite(ledPin, total1);

But this isn't working - I think I read somewhere that ATtiny's can't do serial?? I also tried to get some tone based sketches working too but they aren't either....the core I'm using is this one:

Any advice would be ace - thanks! smiley


Santiago de Chile
Offline Offline
Sr. Member
Karma: 13
Posts: 459
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Attiny85 can do Software Serial, some claim that it works. However you have to set the fuses to 8mhz and external crystal/resonator is desired.

Your attiny core is for Arduino 1.5, i don't use that IDE because if you only use Arduino UNO, Mega and/or attiny I recommend Arduino 1.0.5 for its stability.

I've used the tone library flawlessly with this library (same page, different core version for Arduino 1.0.5)
« Last Edit: September 01, 2014, 02:38:08 pm by mart256 » Logged

Work for what you love

Offline Offline
Faraday Member
Karma: 100
Posts: 6034
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

  I think I read somewhere that ATtiny's can't do serial?? 

Yes and no.

Unlike the UNO, the ATtiny85 does not have an FTDI chip onboard so you need to use Software Serial
Google "ATtiny85 using software serial"

Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,
DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

Pages: [1]   Go Up
Jump to: