Pages: [1]   Go Down
Author Topic: ATtiny Capacitive Sensing and Sound  (Read 119 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
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
WWW
 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()                   
{
   
   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! smiley

Logged

Santiago de Chile
Offline Offline
Sr. Member
****
Karma: 13
Posts: 481
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)
https://code.google.com/p/arduino-tiny/downloads/detail?name=arduino-tiny-0100-0018.zip
« Last Edit: September 01, 2014, 02:38:08 pm by mart256 » Logged

Work for what you love

Offline Offline
Faraday Member
**
Karma: 101
Posts: 6199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"
Logged

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: