Microcontroller functionality

Hi Arduino forums,

I’m working on my own circuit board that I’ve programmed using a UNO.

The microcontroller is an ATtiny85.

I’ve programmed the ATtiny to run through several light functions at the push of a tact switch. Which works quite well on a breadboard.

However, after finishing building my circuit I’ve experienced trouble in the function. I would like the chip to transmit the signal of the button press through a micro usb port to a LED on the opposing end.

I imagine it has something to do with my traces.

PB1 of the tiny is the designated light variable, while PB0 is the button variable. I’ve attempted multiple arrangements of PB1’s trace. Initially I wired it directly to Vin expecting it to turn the light on on the other side of the usb. When this did not work I tried wiring it two GND. Still no such luck.

Attached is a schematic of the most recent board with PB1 wired to GND. IC1 is MIC5225 and IC2 is MCP7381. This board is an adaptation of the Trinket by Adafruit. I initially spoke to them regarding the problem but perhaps it is a conflict of interests. I do not intend to use this board as a programmable microcontroller.

I only intend to used the single LED code applied to it.

Thanks,
-J

circuit board.png

justliketheyusedto: However, after finishing building my circuit I've experienced trouble in the function. I would like the chip to transmit the signal of the button press through a micro usb port to a LED on the opposing end.

I imagine it has something to do with my traces.

Can you explain what in god's name you're doing? That description is totally insufficient, and it makes no sense.

Are you saying you're not using the USB port for USB? If so why are you using a USB connector at all?

You say you're programming it with an Uno, but the connections necessary for this are not broken out, so that's also mysterious.

Also, you haven't posted your code - please post your code, or code that demonstrates your problem.

And a schematic, too, if you would.

The USB port is intended to be a charger port, as well as connect the LED to the board.

The LED and male USB adapter are stationary while the circuit board is detachable.

I pre-programmed the chip before soldering it to the board, that way I didn’t need to make breakouts.

#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
}

That makes a bit more sense. Are you using the USB for communication/programming at all, or just for power? If just for power, don't connect the data lines (at least not like you've done now).

Got a schematic of whatever it's plugging into with the LED?

No unfortunate not but it's simple the LED is soldered positive to Vbus and GND to GND.

No at the moment I'm not using the usb for communication. But it be easier to program the ATtiny that way.

For now I program it on one board, remove it and put it on the test circuit board.

My main concern is turning on the LED through the usb and maintaining all the button functionality.

Do you think disconnecting the data lines and running PB1 to Vbus would do the trick?

I edited the schematic of my board a bit. Removed the reset switch because I wasn’t sure that it was necessary, and removed the connections to the data+ and data-. I Also invested in some 0402 1/16W resistors which has allowed for a much smaller board.

Unfortunately I’m still having a bit of trouble. I built myself a CNC mill for engraving. Works like a charm however I broke my smaller bits accidentally in learning how to operate the machine.

Now the machine keeps breaking a few of the vias on the underside of the board. I believe this is resulting in a open circuit. (I tried repairing these by soldering some leads through the broken vias, but to no avail the positions are just to tight for me to push leads through and I ended up breaking more traces in the process.)

Before that though I was getting little to no power to the top side of the board. And when plugged in to charge the green LED goes on for a moment before the usb is full inserted then back off.

I ordered more bits and they should be here by Wednesday so I’ll get the chance to retest the circuit. Thanks amazon prime!

This means that I’m gonna have to wait before seeing if the connections between the ATtiny85 and the usb port are in the appropriate arrangement to turn on the LED on the apposing end of the usb port.

reminder:
IC1- MCP73831
IC2 -MIC5225
R1&R2- 1k
R3- 10k
R5-2.5k
capacitors 10uf

However my main concern is the connections of the ATtiny. Any advice or thoughts?
The help is greatly appreciated!
-J