I just got myself a Attiny85 from digispark (the one with a normal usb male) and been trying to figure out the following:
What I want:
When I connect the attiny via the buildt in usb on the devboard to a computer, the buildin led (pin 1) should light up IF the attiny recieves data from the computer via the USB.
What I've tried:
My knowledgebase is limited but I viewed multiple libraries (DigiUSB, DigiCBC, SerialUSB) and tried different example codes with my own modifications. Without results.
I can upload and run simple code but Iam clueless in how I can make it stay connected to the PC.
I know that the above is not at all a good explanation but I don't know much about this stuff so if anything is unclear please just ask counter questions and I will do my best to clear it out.
Hello and thank you for your reply!
Well, not necessarily serial. A usb have 4 physical wires (atleast in usb 2.0), 1 for 5v, 1 for GND, 1 for D+ and one for D-. I want to know if anything passes through D+ or D-, aka traffic is recieved from the source Ive plugged the USB into. And if it get's any data then I just want the built in LED on the board to light up.
Wow... this could actually be it! I tried that library before but with 16.5 instead of 16 or 8 (as your link mentions). Will try to make that change and read from the USB pins once more!
EDIT to the below: Now it seems to work Besides that the led wont turn off after (what i think) the data stream is cancelled)
Im new to this so Im unsure if my code is correct... Anyone care to take a look?
Right now the led (pin 1) lights up as if data is recieved (my goal)... but even if i plug it into a power outlet in the wall. So not working
Running the Digispark on 8Mhz (based on my choice in arduino IDE)
#include <SoftwareSerial.h>
const byte rxPin = 3;
const byte txPin = 4;
// Set up a new SoftwareSerial object
SoftwareSerial mySerial (rxPin, txPin);
void setup() {
mySerial.begin(38400);
pinMode(1, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
if (mySerial.available() > 0) {
digitalWrite(1, HIGH);
delay(2000);
}
else {
digitalWrite(1, LOW);
}
}