Skip to content

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

  1. This is the schematic that I used.

  2. This is a DC motor that I controlled.

  3. This is a BJT(Bipolar_junction_transistor) 2N222A, that used to drive the current for the motor.

  4. This is a LED indicator, that shows the state that should be the motor.

  5. This is the communication to the serial monitor.

  1. 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-.

  2. This is the normal FTDI connector, but is connected both the RX and the TX.

  3. This is the SPI connector.

  4. This is a LED indicator of state of the motor.

  5. External power supply connection. It is common only GND with the circuit.

Coding the motor controller

  1. Go to File > Preferences and it will pop-up a window, where you have to paste an link.

  2. This is the URL from this source.

https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json

  1. Go to Tools > Board Manager and it will pop-up a window.

  2. Select the option contributed to filter results.

  3. Install this.

  1. Once is connected your board the serial communication it will be established here.

  2. Select the board ATtiny25/45/85.

  3. Specify the processor ATtiny45.

  4. Select the clock as internal(only for this example I made)16MHz.

  5. Select the programmer(In my case is USBtinyISP).

  1. This is the code I used, that is below.

  2. Here you will see all the messages of success of error that has your code.

  3. 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
  1. I could not show the message on the Serial monitor.
Solutions
  1. 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 :(

V-USB

AVR CDC-RS232

  1. Here I show when I was using the HID Bootloader. Sadly it does not work.

  2. 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

The firmware

Faced problems and solutions working with the AVR CDC-RS232 based on the ATtiny45

Problems
  1. The AVR CDC-RS232based on the ATtiny45 needs special driver to work.

  2. The HID Bootloader it did not work, I did not found the problem.

Solutions
  1. I changed by HID Bootloader.

  2. 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.