12. Output devices¶
-
Group assignment: Measure the power consumption of an output device
-
Individual assignment: Add an output device to a microcontroller board you’ve designed and program it to do something
Controlling output¶
Controlling a motor trough serial communication by using serial monitor¶
-
This is the schematic that I used.
-
This is a DC motor that I controlled.
-
This is a BJT(Bipolar_junction_transistor) 2N222A, that used to drive the current for the motor.
-
This is a LED indicator, that shows the state that should be the motor.
-
This is the communication to the serial monitor.
-
In order to save time, I modified a circuit that I already didRS232 converter (that it does not work). The only modification was removing the resistances from D+ and D-.
-
This is the normal FTDI connector, but is connected both the RX and the TX.
-
This is the SPI connector.
-
This is a LED indicator of state of the motor.
-
External power supply connection. It is common only GND with the circuit.
Coding the motor controller¶
-
Go to File > Preferences and it will pop-up a window, where you have to paste an link.
-
This is the URL from this source.
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
-
Go to Tools > Board Manager and it will pop-up a window.
-
Select the option contributed to filter results.
-
Install this.
-
Once is connected your board the serial communication it will be established here.
-
Select the board ATtiny25/45/85.
-
Specify the processor ATtiny45.
-
Select the clock as internal(only for this example I made)16MHz.
-
Select the programmer(In my case is USBtinyISP).
-
This is the code I used, that is below.
-
Here you will see all the messages of success of error that has your code.
-
Here you will see if the board parameters was selected correctly.
ATtiny packages for Arduino IDE
The code in Arduino C++¶
#include <SoftwareSerial.h> int rx = 1; //Declares the RX pin int tx = 2; //Declares the TX pin SoftwareSerial mySerial(rx, tx); //Setting up the RX/TX pins as a SoftwareSerial char buttonState = '1';//Declares the character that represents the virtual button current state char lastButtonState = '0'; //Declares the character that represents the virtual button last state int ledPin = 3; //Declares the pin where the indicator LED is already attached int motorPin = 0; //Declares the pin where the indicator Motor controller is already attached void setup(){ mySerial.begin(9600); //Start the serial communication and select the its speed that deppends of the frequency that it will be program the attiny pinMode(ledPin, OUTPUT); //Configures the LED pin as an output pinMode(motorPin, OUTPUT); //Configures the Motor pin as an output } void loop() { buttonState = mySerial.read(); //Reads the message a "1" or a "0" from the command line if (buttonState != lastButtonState) { //Checks if there exist a change in the virtual button state if (buttonState == '1') { // Condition For Motor ON mySerial.println("ON"); //Prints in the screen the actual state digitalWrite(ledPin, HIGH); //Turns ON the indicator LED analogWrite(motorPin, 100); //Turns ON the motor with 39.2% of the potency } else if (buttonState == '0'){ // Condition For Motor OFF mySerial.println("OFF"); //Prints in the screen the actual state digitalWrite(ledPin, LOW); //Turns OFF the indicator LED analogWrite(motorPin, 0); //Turns OFF the motor } delay(50); } lastButtonState = buttonState; //Sets the current state as a last state }
Faced problems and solutions working with the hello button¶
Problems¶
- I could not show the message on the Serial monitor.
Solutions¶
- The solution was program the attiny45 with the internal clock to 16MHz, in that way I can set the Bauds to 9600.
Files of the motor controller¶
I spent most of the week trying make to work this circuit.
This is a video demos of the motor controller¶
Failure doing the AVR CDC-RS232 based on the ATtiny45 :(¶
-
Here I show when I was using the HID Bootloader. Sadly it does not work.
-
This is the board connected directly to USB for the Bootloader trial.
Files (If you want to try yourself)¶
Files of the versioned Board for SMD components
Useful links about V-USB¶
Faced problems and solutions working with the AVR CDC-RS232 based on the ATtiny45¶
Problems¶
-
The AVR CDC-RS232based on the ATtiny45 needs special driver to work.
-
The HID Bootloader it did not work, I did not found the problem.
Solutions¶
-
I changed by HID Bootloader.
-
I moved to HID keyboard, to see if I can understand the HID protocol.
What I learned this week?¶
I learned about HID(Human Interface Device) and how it works and how we can use it.