11. Output Devices¶
Todo list¶
Group assignment:
- Measure the power consumption of an output device
- Document your work to the group work page and reflect on your individual page what you learned
Individual assignment:
- Add an output device to a microcontroller board you’ve designed and program it to do something
¶
Servo Motor as output device¶
I used a micro servo as the output device and a light sensor diode as the input device. I want to make a small robot which is like nocturnal animal. It will run away from light.
Connect the board and devices like this:
Code:
#include <Servo.h>
Servo myservo; // deinfe Servo Object
int pos = 0; //
#include <Servo.h>
Servo myservo; // deinfe Servo Object
int pos = 0;
void setup() {
pinMode(0, INPUT);
myservo.attach(1);
}
void loop() {
int value = analogRead(0); //Read value from light sensor
if (value < 1010) {
for (pos = 0; pos <= 180; pos ++) {
// in steps of 1 degree
myservo.write(pos);
delay(2);
}
for (pos = 180; pos >= 0; pos --) {
myservo.write(pos);
delay(2);
}
}
delay(100);
}
Hero Shot¶
Issue¶
I did the upload code when testing the servo, it worked. But when I try to attach the light sensor the board get to totally not responding. Error when uploading code to my antiny412 board:
Sketch uses 1714 bytes (41%) of program storage space. Maximum is 4096 bytes.
Global variables use 85 bytes (33%) of dynamic memory, leaving 171 bytes for local variables. Maximum is 256 bytes.
SerialUPDI
UPDI programming for Arduino using a serial adapter
Based on pymcuprog, with significant modifications
By Quentin Bolsee and Spence Konde
Version 1.2.3 - Jan 2022
Using serial port /dev/cu.usbserial-D30CO4ZF at 57600 baud.
Target: attiny412
Set fuses: ['2:0x02', '6:0x04', '8:0x00']
Action: write
File: /var/folders/hd/pt4q8pqn76z0pyfgh2s5bk900000gn/T/arduino_build_442326/sketch_servo.ino.hex
Traceback (most recent call last):
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/prog.py", line 285, in <module>
main()
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/prog.py", line 128, in main
return_code = pymcuprog_basic(args, fuses_dict)
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/prog.py", line 199, in pymcuprog_basic
status = pymcu._start_session(backend,
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/pymcuprog/pymcuprog_main.py", line 545, in _start_session
backend.start_session(sessionconfig)
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/pymcuprog/backend.py", line 359, in start_session
self.programmer.setup_device(
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/pymcuprog/programmer.py", line 78, in setup_device
self.device_model = get_nvm_access_provider(self.transport,
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/pymcuprog/nvm.py", line 42, in get_nvm_access_provider
accessprovider = NvmAccessProviderSerial(transport, device_info, baud=frequency)
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/pymcuprog/nvmserialupdi.py", line 53, in __init__
self.avr = UpdiApplication(port, baud, self.dut)
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/pymcuprog/serialupdi/application.py", line 70, in __init__
self.phy = UpdiPhysical(serialport, baud_temp)
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/pymcuprog/serialupdi/physical.py", line 29, in __init__
self.initialise_serial(self.port, self.baud)
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/pymcuprog/serialupdi/physical.py", line 50, in initialise_serial
self.ser.open()
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/serial/serialposix.py", line 272, in open
self._reconfigure_port(force_update=True)
File "/Users/tobin/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/serial/serialposix.py", line 435, in _reconfigure_port
termios.tcsetattr(
termios.error: (22, 'Invalid argument')
termios.error: (22, 'Invalid argument')
With the help of local instructor and recall my memory, I might have made a mistake that fried the chip. When I tried to connect the light sensor to the borad, there was no extra VCC and GND port on board. So I used three button batteries to simulate a 5V, but the batteries are actually 3V each, which I thought they are 1.5V each.
Reference¶
BEAM robots are a type of robot that do not use computers. They are typically cheap to make and can be built within a few days—unlike computer-based robots that can be costly, complex and take years to build.