Hey Adafruit forums
My question is regarding the limits of functionality of a microcontroller, specifically the ATtiny85.
Can a signal be carried through a usb junction?
For instance a LED's positive and negative leads are soldered to a micro usb adapter, which then plugged into a circuit board with an ATtiny85 programmed to turn the light on and off from a tact switch. Could the ATtiny in fact send that signal through the usb?
Considering that PB1 be the LED variable and PB0 the button. Would wiring PB1 directly to Vin work? Would the use of D+ and D- be required? Or would PB1 require external connections apart from that of the usb?
Thanks,
-J
Limits of microcontroller functionality
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_carter
- Posts: 29168
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Limits of microcontroller functionality
Are you using a bare attiny85? Or is it part of one of our boards like the trinket?
It sounds like you are using a USB cable just for its wires. There's no actual USB communication going on. In general, this can be done. Just treat the USB cable as you would any other multi conductor cable.
It sounds like you are using a USB cable just for its wires. There's no actual USB communication going on. In general, this can be done. Just treat the USB cable as you would any other multi conductor cable.
- unknown5591
- Posts: 75
- Joined: Mon Jun 13, 2016 8:19 pm
Re: Limits of microcontroller functionality
Thanks for the quick response,
I am using a bare ATtiny85 I've tried this application with a trinket but the only working results I achieved where separate connections to PB1 and GND.
Correct I would like to use the usb to carry the signal from the tact switch. I tried routing PB1 to Vin of the usb thinking it would send the signal that way. In a separate instance I routed PB1 to ground similar to the trinket without any onboard LED, However in both instances nothing happens when I press the tact switch.
I'm pretty positive it isn't my code as I had some major help in writing it and I worked fine on a breadboard. So it must be in the routing. Any thoughts?
-J
I am using a bare ATtiny85 I've tried this application with a trinket but the only working results I achieved where separate connections to PB1 and GND.
Correct I would like to use the usb to carry the signal from the tact switch. I tried routing PB1 to Vin of the usb thinking it would send the signal that way. In a separate instance I routed PB1 to ground similar to the trinket without any onboard LED, However in both instances nothing happens when I press the tact switch.
I'm pretty positive it isn't my code as I had some major help in writing it and I worked fine on a breadboard. So it must be in the routing. Any thoughts?
-J
- adafruit_support_carter
- Posts: 29168
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Limits of microcontroller functionality
Could be many things. Post a photo of your setup showing all your wiring along with the code you are using. Info on the tact switch would also help.
- unknown5591
- Posts: 75
- Joined: Mon Jun 13, 2016 8:19 pm
Re: Limits of microcontroller functionality
Gladly, the circuit is a composite of the trinket and the trinket pro backpack. This is my first attempt at building a complex circuit, so I figure it'd be smart to pair some working examples.
The tact button is off of the Adafruit Push-Button Power Switch Breakout. It has a 1uf ceramic capacitor connecting the pins on the GND side, the other side of the switch has a wire connecting it to PB0 of the circuit board.
The tact button is off of the Adafruit Push-Button Power Switch Breakout. It has a 1uf ceramic capacitor connecting the pins on the GND side, the other side of the switch has a wire connecting it to PB0 of the circuit board.
Code: Select all
#include<avr/interrupt.h> // These are sets of 'library' functions needed
#include<avr/sleep.h>
const int switchPin = 2;
const int statusLED = 1;
uint8_t onOff;
volatile uint8_t buttonPushCounter = 0;
volatile uint32_t pressStart = 0;
volatile uint32_t pressEnd = 0;
void init_interrupt() { // A function to set up the button press
GIMSK|=_BV(PCIE); // interrupt. It fires on any change on the pin
PCMSK|=_BV(PCINT2); // so on press or release of the button.
sei();
} // end of init_interrupt
ISR(PCINT0_vect) { // This is the function the interrupt triggers
if(digitalRead(switchPin) == LOW) { // low will indicate the button press
//buttonPushCounter += 1; // increment the button press counter
pressStart = millis(); // start/enable a 'soft' timer
}
else { // high indicates release
buttonPushCounter += 1; // or increment on release (better I think)
pressEnd = millis(); //
} // Plus it wakes the trinket up from sleep of course
} //end of ISR
void setup() {
pinMode(switchPin, INPUT_PULLUP);
pinMode(statusLED, OUTPUT);
onOff = HIGH;
init_interrupt(); // set up the button interrupt
//Flash quick sequence so we know setup has started i.e. power applied
for(int k=0;k<10;k=k+1){
if(k%2==0){
digitalWrite(statusLED,HIGH);
}
else{
digitalWrite(statusLED,LOW);
}
delay(250);
} // end of flashing routine
} // end of setup
void loop() {
if(pressEnd) { // Button press released and can be measured
if((pressEnd - pressStart) > 1000) { // if it was pressed longer than a second
onOff = !onOff; // toggle device on or off
}
pressStart = 0; // disable the 'soft' timer (see line 82)
pressEnd = 0;
}
if(onOff) { // if switched on, run the switch statement
switch(buttonPushCounter)
{
case 1:
digitalWrite(statusLED,HIGH); // full LED on 1st press
break;
case 2:
analogWrite(statusLED,127); // next press set the led to half
break;
case 3:
analogWrite(statusLED,85); // quarter
break;
case 4:
analogWrite(statusLED,45); // and dimmer
break;
case 5:
analogWrite(statusLED,15); // dimmest
break;
case 6:
digitalWrite(statusLED,HIGH);
delay(50);
digitalWrite(statusLED,LOW);
delay(50);
break;
default:
buttonPushCounter = 1; // another press or any other unforeseen roll over counter
break;
} // end of switch
} // end of on functionality
else { // if switched off
if(!pressStart) { // ...and not currently timing a button
digitalWrite(statusLED,LOW); // lights out
buttonPushCounter = 0; // counter back to 0
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // go to sleep
sleep_enable();
sleep_cpu();
sleep_disable();
}
} // end of off functionality
}
- Attachments
-
- circuit board.png (81.34 KiB) Viewed 275 times
- unknown5591
- Posts: 75
- Joined: Mon Jun 13, 2016 8:19 pm
Re: Limits of microcontroller functionality
Forgot to mention in the circuit PB1 is wired to GND like a trinket. MCP73831 is IC1 and MIC5225 is IC2.
As I stated earlier my first attempt was wiring PB1 to Vin. This was just the most recent schematic.
I wired a switch to reset but am unsure if it is necessary in this application. If pressed would this reset the attiny removing its code?
As I stated earlier my first attempt was wiring PB1 to Vin. This was just the most recent schematic.
I wired a switch to reset but am unsure if it is necessary in this application. If pressed would this reset the attiny removing its code?
- adafruit_support_carter
- Posts: 29168
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Limits of microcontroller functionality
Ah. Looks like you're working up your own custom board. Neat. I'm limited in my ability to help you troubleshoot it though. It might be helpful to prototype things on a breadboard first.
Hopefully you'll get some traffic and feedback from others. Good luck!
Hopefully you'll get some traffic and feedback from others. Good luck!
- unknown5591
- Posts: 75
- Joined: Mon Jun 13, 2016 8:19 pm
Re: Limits of microcontroller functionality
Thanks for the thoughts.
-J
-J
Please be positive and constructive with your questions and comments.