Go Down

Topic: ATtiny Capacitive Sensing and Sound (Read 267 times) previous topic - next topic

me-backwards

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()                   
{
   
   Serial.begin(9600);
}

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);
  delay(10);
}

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: https://code.google.com/p/arduino-tiny/downloads/detail?name=arduino-tiny-0150-0020.zip

Any advice would be ace - thanks! :)


mart256

#1
Sep 01, 2014, 09:30 pm Last Edit: Sep 01, 2014, 09:38 pm by mart256 Reason: 1
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)
https://code.google.com/p/arduino-tiny/downloads/detail?name=arduino-tiny-0100-0018.zip

raschemmel

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


Yes and no.
  http://www.instructables.com/id/Easy-ATTiny-Serial-Communication-with-Tiny-AVR-Pro/

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,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

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