attiny85 ADC question...

Working with the ADCtouch library, I can not get it to work with the attiny85. I'm wondering if there is something that needs to be changed with how the ADCtouch library sets up the ADC for the attiny, but I don't know enough about ADC to figure this out. Hoping there is an attiny guru out there that can help?

My code:

#include <ADCTouch.h>
 
int ref0, maximum;
int ledPin = 1;
int analogPin = A2;
 
void setup()
{
  pinMode(ledPin, OUTPUT);
  ref0 = ADCTouch.read(analogPin, 500);
  maximum = 85;  
}
 
void loop()
{
    int value0 = ADCTouch.read(analogPin, 500);
 
    value0 -= ref0;

    if (value0 > maximum)
      maximum = value0;

    int brightness = max(min(map(value0,maximum,0,0,255),255),0);

    analogWrite(ledPin, brightness);

    delay(10);
    
}

ADCtouch.read() code:

int ADCTouchClass::read(byte ADCChannel, int samples)
{
	long _value = 0;
	for(int _counter = 0; _counter < samples; _counter ++)
	{
		pinMode(ADCChannel, INPUT_PULLUP);
		
		ADMUX |=   0b11111;
		ADCSRA |= (1<<ADSC); //start conversion
		while(!(ADCSRA & (1<<ADIF))); //wait for conversion to finish
		ADCSRA |= (1<<ADIF); //reset the flag
		
		pinMode(ADCChannel, INPUT);
		_value += analogRead(ADCChannel);
	}
	return _value / samples;
}

Working with the ADCtouch library

There is NOT a core library with that name. You need to post a link to it, rather than assuming that we know what you are talking about.

Here's a link:
http://playground.arduino.cc/Code/ADCTouch

However, the entirety of that library consists of the read() method I also posted.

Here is what I am trying to accomplish with the attiny85: single wire touch capacitance sensing. Here is how the touchADC "library" handles it:

  1. charge the test pin to 5V via pullup resistor
  2. discharge the internal ~14pF capacitor
  3. set the pin to tristate
  4. connect the 14pF capacitor with the pin so that charge distributes evenly
  5. measure the voltage of the internal cap with analogRead()

This works if I use my Arduino Uno, but I can't get it to work with the attiny85. The analog read (#5 in the list above) always returns 0.

I figured it out. For future searches ending up at this topic, I had to change the ADMUX value from 0b11111 to 0b1101 (GND). I also had to play around with the prescaler values, 64 worked for me running at 8mhz.

Hey I searched on "ATtiny85 ADCTouch" before posting about it, and this was exactly what I was looking for! Thanks! I made a modified library for it if you are interested (my first time making a library), it works really well. It will sense your hand from ~2" away with a 1.5" piece of wire and a 1.5" square of Al foil on the end of it. Perfect for the project I was developing! Thanks again!

Hey there! I know it was a while since this thread was posted, but it is EXACTLY what i am looking for. however I just can't seem to make it work. It works through the arduino but not the ATTiny

I've changed the ADMUX in the ADC library as mentioned, connected an LED to ATTiny pin 0 and wire with foil end to pin 3 = A2, but nothing happens. However, the small lamp on the Arduino board close to the GND and 13 pin reacts when i touch the foil, so the system is obviously regestering something, but not sending current through the LED.

I am greatful for the help!!

Hola, veo que perigalacticon, pudo hacer una biblioteca para este tema, podrías subirla por favor gracias.
Saludos