background image

the LED.

The A-Star 32U4 boards are similar enough to the Arduino Leonardo that you do not
actually have to install the add-on. If you want to, you can just select the “Arduino
Leonardo” board in the Arduino IDE. Note that if you upload a sketch to the device this
way, your computer will then recognize it as a Leonardo (for example, its entry in the
Windows Device Manager will display “Arduino Leonardo”).

After you succeed in programming your device from the Arduino IDE, there are many resources you
can use to learn more:

• The Arduino IDE has many

examples

[http://arduino.cc/en/Tutorial/HomePage]

that can run on A-

Stars.

• The Arduino website has a

Language Reference

[http://arduino.cc/en/Reference/HomePage]

, a

wiki called the

The Arduino Playground

[http://playground.arduino.cc/]

, and other resources.

• The A-Star 32U4 boards are similar to the

Arduino Leonardo

[https://www.pololu.com/product/

2192]

and

Arduino Micro

[https://www.pololu.com/product/2188]

so you can search the Internet

for relevant projects that use one of those boards.

• The Related Resources section lists many more resources.

5.3. Programming using avr-gcc and AVRDUDE

This section explains how to program our 32U4 family of boards using the avr-gcc toolchain and
AVRDUDE. This section is intended for advanced users who do not want to use the Arduino IDE as
described in the previous section.

Getting the prerequisites

If you are using Windows, we recommend downloading

WinAVR

[http://winavr.sourceforge.net/]

which

contains the avr-gcc toolchain and a command-line utility called

AVRDUDE

[http://www.nongnu.org/

avrdude/]

that can be used to upload programs to the A-Star bootloader. If the version of GNU Make

that comes with WinAVR crashes on your computer, we recommend using the

Pololu version of GNU

Make

[https://github.com/pololu/make/releases]

.

If you are using Mac OS X, we recommend downloading the

CrossPack for AVR Development

[http://www.obdev.at/products/crosspack]

.

If you are using Linux, you will need to install avr-gcc, avr-libc, and AVRDUDE. Ubuntu users can get
the required software by running:

Pololu Balboa 32U4 Balancing Robot User’s Guide

© 2001–2019 Pololu Corporation

5. Programming the Balboa 32U4

Page 74 of 97

Summary of Contents for Balboa 32U4

Page 1: ...Pololu Balboa 32U4 Balancing Robot User s Guide Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation https www pololu com docs 0J70 all Page 1 of 97 ...

Page 2: ...ion Kit 41 3 14 Schematics and dimensions 43 4 Assembling the Balboa 32U4 kit 45 5 Programming the Balboa 32U4 67 5 1 Installing Windows drivers 67 5 2 Programming using the Arduino IDE 69 5 3 Programming using avr gcc and AVRDUDE 74 6 Balboa 32U4 Arduino library 77 7 How to make a Balboa balance 78 7 1 Sensor measurements 78 7 2 An example balancing algorithm 80 8 The Balboa 32U4 USB interface 87...

Page 3: ...rface for user input while indicator LEDs a buzzer and a connector for an optional LCD allow the robot to provide feedback The Balboa 32U4 can be used either as a standalone control solution or as a base for a more powerful Raspberry Pi controller Its on board connector and mounting holes allow a compatible Raspberry Pi Model B or newer including Pi 3 Model B https www pololu com product 2759 and ...

Page 4: ...re also accessible enabling sensors and other peripherals to easily be connected A software add on is available that makes it easy to program a Balboa 32U4 robot from the Arduino environment and we have Arduino libraries and example sketches to help get you started A USB A to Micro B cable https www pololu com product 2072 not included is required for programming 1 1 Included components Pololu Bal...

Page 5: ... two gearbox covers six 683 ball bearings two 3 mm D shafts ten plastic pinion gears small two each with 17 19 21 23 and 25 teeth ten plastic output gears large two each with 41 43 45 47 and 49 teeth battery terminals Balboa 32U4 control board https www pololu com product 3576 and related parts buzzer https www pololu com product 1484 Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Polol...

Page 6: ...2599 12 CPR four 3 16 2 56 screws and nuts bumper cage kit https www pololu com product 3574 which includes four bumper skids four bumper cage cross bars two bumper skid spacers twelve 12 mm M3 screws and nuts Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 1 Overview Page 6 of 97 ...

Page 7: ...Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 1 Overview Page 7 of 97 ...

Page 8: ... a number of additional components and tools to complete your Balboa robot the most important of which are motors and wheels Since the Balboa 32U4 robot kit works with a variety of motors and wheels motors and wheels are not included this means you can choose your own to personalize your robot Motor selection Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 1 Overview P...

Page 9: ...gear ratio and speed is inversely proportional so as the gear ratio gets bigger the torque increases while the speed decreases Micro metal gearmotor HPCB with extended motor shaft The kit includes magnetic encoder discs and the encoder sensors are built into the Balboa 32U4 control board so you do not need to order encoders with your motors Wheel selection We recommend using the Balboa with 80 10m...

Page 10: ...u com product 2072 to connect the board to your computer for programming and debugging soldering iron and solder we recommend one with adjustable temperature control like the Hakko FX 888D Digital Soldering Station https www pololu com product 2779 small Phillips screwdriver wire cutter https www pololu com product 159 for trimming leads Optional tools small pair of pliers https www pololu com pro...

Page 11: ... pololu com product 1968 and nuts https www pololu com product 1967 for mounting it The Balboa is intended to be used with our standoffs with 4 mm threads https www pololu com product 2713 Our standoffs with longer 6 mm threads will interfere with the chassis 5 Channel Reflectance Sensor Array https www pololu com product 3577 for identifying changes in reflectance on the ground directly underneat...

Page 12: ...C V2 balance charger discharger https www pololu com product 2588 that can be also used for this 1 3 Supported operating systems The Balboa 32U4 control board can be programmed using any operating system that supports the Arduino environment This includes Microsoft Windows 10 8 1 8 7 Vista XP with Service Pack 3 Linux and macOS Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corpo...

Page 13: ...ou can contact us https www pololu com contact directly or post on our forum http forum pololu com Tell us what we did well what we could improve what you would like to see in the future or anything else you would like to say Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 2 Contacting Pololu Page 13 of 97 ...

Page 14: ...o transmit and receive data from the computer and program the board over USB The USB connection can also provide power for the microcontroller and most of the other hardware on the board but not motor power see Section 3 6 for more details The control board s ATmega32U4 comes preloaded with the Arduino compatible A Star 32U4 USB bootloader https www pololu com docs 0J66 7 which allows it to be eas...

Page 15: ...s see below The remaining two LEDs are power indicators and they are located in the top left corner of the board near the USB connector A blue power LED indicates when the controller is receiving power from the Balboa s batteries the power switching circuit must be turned on A green power LED indicates when the USB bus voltage VBUS is present Pushbuttons The Balboa 32U4 control board has five push...

Page 16: ...th a low profile male header https www pololu com product 2663 or any other LCD with the common HD44780 parallel interface https www pololu com file 0J71 DMC50448N AAE AD pdf 109k pdf You can adjust the LCD contrast with the potentiometer directly above the LCD connector We recommend using a 2 mm slotted screwdriver to adjust the contrast The Balboa32U4 library provides functions to display data o...

Page 17: ... facing For more information about the drivers see the DRV8838 datasheet https www pololu com file 0J806 drv8838 pdf 1MB pdf We also sell a carrier board https www pololu com product 2990 for this driver The Balboa32U4 library provides functions that allow you to easily control the motors and it can optionally take care of flipping a direction signal for you if you accidentally soldered in a motor...

Page 18: ...ratios more accurately specified as 51 45 1 are used along with the plastic gears that give an additional 2 88 1 reduction the encoders provide 51 45 2 88 12 1778 CPR Quadrature encoder transitions are often detected by monitoring both encoder channels directly However since transitions on the Balboa s encoders can occur at high frequencies several thousand per second when its motors are running i...

Page 19: ...forms in the diagram above would be produced by forward rotation Note that forward refers to the rotation direction that would cause a balancing Balboa to move in the direction its battery cover is facing The Balboa32U4 library provides appropriate interrupt service routines and functions for reading the encoders and keeping track of their counts see Section 6 3 5 Inertial sensors Pololu Balboa 32...

Page 20: ... 9 such as our Arduino AHRS example https github com pololu minimu 9 ahrs arduino can also be adapted to work on Balboa Please note that the LIS3MDL magnetometer can be affected by magnetic fields from the Balboa itself These include magnets in the motors and encoders electrical currents through the board and hard iron distortions from metal probably mostly from the batteries The magnetometer is p...

Page 21: ...ibrary can be used to determine the battery voltage from this reading Power switch circuit The Balboa 32U4 control board uses the patented latching circuit from the Pololu pushbutton power switch https www pololu com product 2808 which provides a solid state power switch for your robot controlled with the on board pushbutton By default this pushbutton can be used to toggle power one push turns on ...

Page 22: ... to set the switch state Note that this pin should not be driven high at the same time the OFF pin is driven high GATE With pushbutton operation disabled button jumper cut this pin controls the state of the switch circuit driving it low turns the switch on while letting it float turns the switch off Connect through slide or toggle switch to ground for on off operation Leave this pin disconnected o...

Page 23: ...elect the higher of the two sources which will typically be the USB 5 V bus voltage if the control board is connected to USB Consequently when Balboa 32U4 is connected to a computer via USB it will receive 5 V logic power even when the power switch is off This can be useful if you want to upload or test a program without drawing power from the batteries and without operating the motors It is safe ...

Page 24: ...ution VBAT is connected to the battery contact labeled BAT and provides a direct connection to the battery supply VSW is the battery voltage after reverse voltage protection and the power switch circuit VREG is the output of the on board 5 V regulator 5V is the output of the TPS2113A power multiplexer circuit which is connected to VREG by default but switches to 5 V USB power if VREG is too low 3V...

Page 25: ...Pinout diagram of the Balboa 32U4 control board ATmega32U4 pinout and peripherals Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 3 Balboa 32U4 in detail Page 25 of 97 ...

Page 26: ... the Balboa 32U4 control board Raspberry Pi pinout and peripherals level shifter and board power control Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 3 Balboa 32U4 in detail Page 26 of 97 ...

Page 27: ...unting locations for a connector and two standoffs matching part of the Raspberry Pi HAT Hardware Attached on Top specification and it is designed to connect to the Model B and newer versions of the Raspberry Pi with 40 pin GPIO headers including the Raspberry Pi 3 Model B https www pololu com product 2759 and Model A https www pololu com product 2760 Pololu Balboa 32U4 Balancing Robot User s Guid...

Page 28: ...tion When used with a Raspberry Pi the control board is designed to serve as an auxiliary controller communicating with the Raspberry Pi using an I C interface also known as 2 wire Serial Interface or TWI As such the ATmega32U4 microcontroller s I C data and clock lines SDA and SCL are connected to the corresponding lines on the Raspberry Pi s I C bus 1 through on board level shifting circuits The...

Page 29: ...ill be releasing an updated tutorial with steps specific to the Balboa soon Raspberry Pi robot using the A Star 32U4 Robot Controller General purpose level shifter In addition to the dedicated I C level shifters the board also makes available a single channel tristatable unidirectional level shifter that is not connected to any signals by default Four pins are exposed OE output enable IN input OUT...

Page 30: ...tails about how power is shared and can be controlled between the two boards ID EEPROM The Balboa 32U4 control board includes a 32 kilobit 4096 byte EEPROM that connects to the Raspberry Pi s ID_SD and ID_SC pins The EEPROM ships with its contents blank but you can program it as an ID EEPROM in the format specified by the Raspberry Pi HAT specifications https github com raspberrypi hats using the ...

Page 31: ...uino environment for the pin These names can generally be used as arguments to any function that takes a pin number However there are some exceptions For example passing the number 4 to analogRead actually reads pin A4 not pin 4 Also due to hardware limitations some functions only work on a limited set of pins The Balboa 32U4 functions column documents what the pin is used for on the Balboa 32U4 c...

Page 32: ...D RX User pushbutton C LCD data line DB5 SPI slave select SS Pin change interrupt PCINT0 PC7 13 LED_BUILTIN Yellow LED LCD data line DB6 Timer4 PWM output A OC4A Timer3 input capture pin ICP3 Divided system clock output CLKO PD5 30 LED_BUILTIN_TX Green LED TX User pushbutton B LCD data line DB7 UART external clock XCK1 UART flow control CTS PD7 6 A7 25 Buzzer PWM Analog input ADC10 Timer4 PWM outp...

Page 33: ...errupt PCINT5 PB1 15 SCK Right motor direction SPI Clock SCK Pin change interrupt PCINT1 ISP programming line SCK PB4 8 A8 26 Left encoder XORed input Analog input ADC11 Pin change interrupt PCINT4 PE2 Left encoder input Hardware bootloader select HWB PE6 7 Right encoder XORed input Analog comparator negative input AIN0 External interrupt source INT6 PF0 A5 23 Right encoder input Analog input ADC0...

Page 34: ...C4A PD6 12 A11 29 Free I O Analog input ADC9 Timer4 PWM output D OC4D Timer1 counter source T1 PF7 A0 18 Free I O Analog input ADC7 JTAG test data in TDI PF5 A2 20 Free I O Analog input ADC5 JTAG test mode select TMS PF4 A3 21 Free I O Analog input ADC4 JTAG test clock TCK PF1 A4 22 Free I O Analog input ADC1 RESET Reset pushbutton internally pulled high active low AREF Analog reference 3 10 Addin...

Page 35: ...want to connect you can gain access to a few more I O pins on the LCD connector With no LCD pin 11 PB7 and pin 4 A6 PD4 are free Both pins can be used for digital input and output In addition pin 11 can be used as a PWM output and a pin change interrupt and pin 4 can be used as an analog input If you do not have an LCD connected you can use the LCD contrast potentiometer for other purposes The out...

Page 36: ...ower whenever the batteries are installed and the power is on but they cannot be powered from USB If you power them from a 5V pin then they will receive 5V power whenever the control board s logic components are powered If you power them from 3V3 they will receive 3 3V power whenever the control board s logic components are powered For more information about these power nodes and how much current ...

Page 37: ...sembling the bumper cage to achieve particular angles with respect to the horizontal These diagrams all use the 80mm wheel note that the angles will differ when using different diameter wheels Note that the bumper skids on either side of the robot can be adjusted independently from the other side allowing for asymmetric configurations The arms can be flipped to achieve some additional angles as sh...

Page 38: ...d on the Balboa in various positions the top pictures show various inclined positions available while the bottom picture shows the declined positions Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 3 Balboa 32U4 in detail Page 38 of 97 ...

Page 39: ...Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 3 Balboa 32U4 in detail Page 39 of 97 ...

Page 40: ...age diagrams pdf 2MB pdf Additionally the included spacers can be used in place of the pair of bumper skids on either side of the robot and allow you to use just one side of the bumper cage Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 3 Balboa 32U4 in detail Page 40 of 97 ...

Page 41: ...sory kit is an add on extension for the Balboa chassis that provides additional mounting options and support for a ball caster Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 3 Balboa 32U4 in detail Page 41 of 97 ...

Page 42: ...nal differential drive applications See Section 4 for assembly details Note that using different diameter wheels on the Balboa with the Stability Conversion Kit produces different decline angles for the robot The diagrams below show the Stability Conversion Kit Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 3 Balboa 32U4 in detail Page 42 of 97 ...

Page 43: ...4 control board schematic diagram https www pololu com file 0J1267 balboa 32u4 control board schematic pdf 587k pdf Dimensions The following DXF shows the main board outline along with the sizes and locations of all of the holes on the board Balboa 32U4 control board drill guide https www pololu com file 0J1265 bal01a drill dxf 285k dxf The following picture shows the approximate dimensions of the...

Page 44: ...Dimensions of the Balboa 32U4 Balancing Robot with 80 10mm wheels Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 3 Balboa 32U4 in detail Page 44 of 97 ...

Page 45: ... now is a good time to solder in the buzzer to the Balboa 32U4 control board 2 Optional This is a convenient time to add any other optional electronics or headers such as a 2 20 female header https www pololu com product 1037 for mounting a Raspberry Pi Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 45 of 97 ...

Page 46: ...e protruding out of the top of the board as shown Battery contacts and electronics 4 Set aside the Balboa 32U4 control board and insert the double sided battery contacts as shown below Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 46 of 97 ...

Page 47: ...atteries 5 Flip the chassis over and insert the two individual battery contact terminals into the top of the chassis 6 Place the Balboa 32U4 control board on the chassis making sure the battery terminals insert into the slots on the board Secure the board in place using the four included 2 56 screws Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balbo...

Page 48: ...and nuts 7 Solder the battery terminals to the Balboa 32U4 control board Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 48 of 97 ...

Page 49: ...ated When the Balboa is fully assembled and balancing upright the positive motor terminal should be closer to the top When properly seated in the slot the face plate of the motor gearbox will be flush with the edge of the slot Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 49 of 97 ...

Page 50: ... clip up until the tabs are seated in the slots and rotating the clip into position until you hear it click into place 10 Clip the motor wires to an appropriate length and solder them to the motor terminals Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 50 of 97 ...

Page 51: ...t and align with the sensors on the Balboa 32U4 control board 12 Repeat steps 8 through 11 for the second motor again making sure the terminal of the motor is toward the longer end of the board Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 51 of 97 ...

Page 52: ... that the tooth count is also indicated on the side of the output gears 14 Press two ball bearings into the gearbox cover 15 Place another ball bearing into the gearbox housing on the chassis and insert the round side of the 3 mm D shaft the D shape should be facing outwards Next press your selected gears onto the two shafts making sure they align properly and install the gearbox cover Double chec...

Page 53: ... outer surface of the wheel One way to do this is to set the wheel on a flat surface and line the chassis up with it so that the flat part of the motor s D shaft aligns correctly with the wheel Then lower the chassis pressing the motor shaft into the wheel until it contacts the surface Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Pag...

Page 54: ...he correct orientation for the batteries is indicated by the battery shaped holes in the Balboa chassis as well as the and indicators in the battery compartment of the chassis Once they are installed secure the battery compartment cover Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 54 of 97 ...

Page 55: ...The basic assembly of your Balboa chassis is now complete Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 55 of 97 ...

Page 56: ...Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 56 of 97 ...

Page 57: ...e ball caster to make the Balboa taller and give it more mounting options To assemble the optional ball caster start by placing the rollers into the cutouts in the Stability Conversion Kit Next place the 1 plastic ball on the top of the three rollers and push the ball caster retention clip over the ball and into the chassis so the three legs snap into their respective mounting slots You should hea...

Page 58: ... into place Optionally you can use the two mounting holes located just outside of the clips to further secure the Stability Conversion Kit to the Balboa chassis These mounting holes are intended for M3 screws and nuts Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 58 of 97 ...

Page 59: ...ling back on the clips If you have the Balboa 32U4 control board or other electronics mounted on the Balboa chassis you might consider using a small screwdriver to help reach the clips Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 59 of 97 ...

Page 60: ...tronics The bumper cage has numerous mounting holes that can be used to adjust the positioning Details about the various mounting options can be found in Section 3 12 The bumper cage mounts to the side rails of the Balboa chassis with M3 screws 12 mm length and nuts The bumper cage is made up of four bumper skids and four bumper cage cross bars The pictures below show the process of mounting the b...

Page 61: ...Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 61 of 97 ...

Page 62: ...s as needed along the slots or in the designated mounting holes on each bumper skid They can be rotated before tightening down the mounting screws to better accommodate additional hardware Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 62 of 97 ...

Page 63: ...Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 63 of 97 ...

Page 64: ...h allow just one side of the bumper cage to be used This is achieved by substituting one set of bumper skids with the spacers Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 64 of 97 ...

Page 65: ...nly protect electronics but also add uniqueness and creativity to your robot The pictures below show two such home made examples Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 4 Assembling the Balboa 32U4 kit Page 65 of 97 ...

Page 66: ...695 so those with access to 3D printers can print their own For everyone else you can improvise your own bumpers using everyday objects like LEGO blocks wood or cardboard and mount them to the side rails of the chassis with M3 screws and nuts https www pololu com product 1069 the screws in the LEGO arm picture are 12 mm long Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporat...

Page 67: ...otfix have reported problems that were solved by upgrading to Service Pack 3 so we recommend Service Pack 3 over the hotfix Before you connect your Pololu A Star 32U4 or another of our 32U4 family of boards to a computer running Microsoft Windows you should install its drivers 1 Download the A Star Windows Drivers https www pololu com file 0J1240 a star windows 1 3 0 0 zip 7k zip and extract the Z...

Page 68: ...been connected to before Windows XP users After installing the drivers you will need to follow steps 5 9 for each new A Star device you connect to your computer You will also need to follow these steps the first time you attempt to program the device in order to make Windows recognize the bootloader and when you connect the device to a different USB port that it has not been connected to before 5 ...

Page 69: ...Windows 10 or later and choose not to install the drivers the A Star will still be usable To tell which USB Serial Device in your Device Manager is the A Star double click on each one and look at the Hardware Ids property in the Details tab An A Star running a sketch will have the ID USB VID_1FFB PID_2300 MI_00 while an A Star in bootloader mode will have the ID USB VID_1FFB PID_0101 If you want t...

Page 70: ...y other URLs in the box you can either add this one separated by a comma or click the button next to the box to open an input dialog where you can add the URL on a new line Adding a Boards Manager index for Pololu boards in the Arduino IDE s Preferences dialog 3 Click the OK button to close the Preferences dialog Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 5 Progra...

Page 71: ...4 entry If you do not see your device listed in the Board menu try restarting the Arduino IDE Selecting the Pololu A Star 32U4 in the Boards menu 9 In the Tools Port menu select the port for the device On Windows you can determine what COM port the device is assigned to by looking at the Ports COM LPT section of the Device Manager On Linux the port name will begin with dev ttyACM On Mac OS X the p...

Page 72: ...up It is OK to close the first window Selecting the Blink example in the Arduino IDE 11 Press the Upload button to compile the sketch and upload it to the device If everything goes correctly you will see the message Done uploading appear near the bottom of the window If you are using Windows and you have not previously programmed an A Star device on this Pololu Balboa 32U4 Balancing Robot User s G...

Page 73: ...trouble connecting to the port or using it try unplugging the device closing any programs that might be using the serial port restarting the Arduino IDE and then plugging the device back in Uploading a sketch to the A Star using the Arduino IDE 12 If you uploaded the Blink sketch then the yellow LED should be blinking once every two seconds However we ship some A Stars with that same example alrea...

Page 74: ...ojects that use one of those boards The Related Resources section lists many more resources 5 3 Programming using avr gcc and AVRDUDE This section explains how to program our 32U4 family of boards using the avr gcc toolchain and AVRDUDE This section is intended for advanced users who do not want to use the Arduino IDE as described in the previous section Getting the prerequisites If you are using ...

Page 75: ...ga32u4 CFLAGS g Wall mcall prologues mmcu MCU Os LDFLAGS Wl gc sections Wl relax CC avr gcc TARGET main OBJECT_FILES main o all TARGET hex clean rm f o hex obj hex hex obj avr objcopy R eeprom O ihex obj OBJECT_FILES CC CFLAGS OBJECT_FILES LDFLAGS o program TARGET hex avrdude p MCU c avr109 P PORT U flash w TARGET hex Make sure that the PORT variable in the Makefile is set to the name of the devic...

Page 76: ...ode first One way to do this is to reset the AVR twice within 750 ms Most of the boards in our 32U4 family have a reset button that can be used to reset the board On any of our 32U4 family of boards a pushbutton can be connected between the GND and RST pins to serve as a reset button or you can use a wire Once the device is in bootloader mode quickly run the command make program to program it If y...

Page 77: ...ketchbook directory You can view your sketchbook location by opening the File menu and selecting Preferences in the Arduino IDE If there is not already a libraries folder in that location you should make the folder yourself 4 After installing the library restart the Arduino IDE After you install the Balboa32U4 library you can learn more about it by trying the included example sketches and by readi...

Page 78: ... make an AHRS attitude and heading reference system a system that gives the robot a sense of its orientation in three dimensions AHRS software is particularly important in aviation drone applications but for basic balancing you don t need anything that complicated In fact a single gyro channel the y axis is enough to determine the robot s angle of rotation relative to vertical The gyroscope s y ax...

Page 79: ...you have calibrated the gyro and estimated the starting angle your angle measurement will tend to drift over time maybe a few degrees in a minute In a full AHRS you use the accelerometer to eliminate drift but for a balancing robot we can use a simpler trick if the robot is successfully 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 void se...

Page 80: ...ed in the previous section gave us two important variables angle the angle relative to vertical angleRate the rate of rotation When thinking about these variables it is helpful to make a plot that shows the trajectory of the robot over time Suppose we take a Balboa with its motors off start it leaning forward and give it a little push toward vertical Initially angle is positive and angleRate is ne...

Page 81: ...s over onto its other side This time it continues rotating as it passes through vertical then falls backwards onto the floor Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 7 How to make a Balboa balance Page 81 of 97 ...

Page 82: ...eriment A value of 140 worked well for the units we used and our Balboa s configuration 1 2 3 4 5 6 7 8 9 10 11 This variable measures how close we are to our basic balancing goal being on a trajectory that would cause us to rise up to the vertical position with zero speed left at the top This is similar to the fallingAngleOffset used for LED feedback and a calibration procedure discussed at the e...

Page 83: ...e the one above save itself It needs to apply just enough backwards acceleration to bump it up onto that ideal dashed gray line We don t know the exact relationship between acceleration and change in rate of rotation and acceleration is not actually instantaneous but the basic point is that we should adjust our motor speed by a factor proportional to the risingAngleOffset variable determined earli...

Page 84: ... distance and speed are our encoder based measurements of how far the robot is from its starting point and how fast it is going each variable is multiplied by a constant that must be calibrated experimentally The final result is similar to a PID algorithm but it responds to both rotational and translational motion with a single output the motor speed You can probably get similar results just by st...

Page 85: ...e with each of the eight possible color combinations indicating a different eighth of the graph The figure below shows the LED colors in each section of the graph along with the approximate trajectory of the robot after being pushed so that you can try to follow along with the video Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 7 How to make a Balboa balance Page 85 ...

Page 86: ... two large corrections while in reality it is constantly making small adjustments to the motor speed It s actual trajectory might look like a smoothed out version of the blue line without sharp corners See our Balancer example code https github com pololu balboa 32u4 arduino library tree master examples Balancer for more details and tips on calibration Pololu Balboa 32U4 Balancing Robot User s Gui...

Page 87: ...you will see additional child devices as well On a Windows computer you can see the virtual serial port by going to your computer s Device Manager and expanding the Ports COM LPT list You should see a COM port labeled Pololu A Star 32U4 In parentheses after the name you will see the name of the port e g COM3 or COM4 Windows will assign a different COM port number to the device depending on what US...

Page 88: ...receive bytes from the virtual serial port using any terminal program that supports serial ports Some examples are the Serial Monitor in Arduino IDE the Pololu Serial Transmitter Utility https www pololu com docs 0J23 Br y Terminal http sites google com site terminalbpp PuTTY http www chiark greenend org uk sgtatham putty TeraTerm http ttssh2 sourceforge jp Kermit http www columbia edu kermit ck80...

Page 89: ...ts the programming commands defined in AVR109 http www atmel com images doc1644 pdf The bootloader always runs first immediately after the AVR is reset Startup logic The main difference between the A Star 32U4 Bootloader and Caterina is in the startup logic This is the part of the bootloader that runs immediately after the AVR is reset and it decides whether to run the user program or run the rest...

Page 90: ...ega32U4 boards our 32U4 family of boards have brown out detection enabled The brown out threshold is 4 3 V and if the voltage on VCC goes below this then the AVR will reset Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 9 The A Star 32U4 Bootloader Page 90 of 97 ...

Page 91: ...could put in your setup function for detecting brown out resets 1 2 3 4 5 6 7 8 9 10 11 12 13 14 pinMode 13 OUTPUT if MCUSR 1 BORF A brownout reset occurred Blink the LED quickly for 2 seconds for uint8_t i 0 i 10 i digitalWrite 13 HIGH delay 100 digitalWrite 13 LOW delay 100 MCUSR 0 Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 9 The A Star 32U4 Bootloader Page 91 o...

Page 92: ...in case your usual method of programming is not working These instructions were developed for the Arduino IDE versions 1 0 5 r2 and 1 6 0 and they might need to be modified for future versions Reset button If you have an A Star 32U4 Micro you should connect a momentary pushbutton https www pololu com product 1400 between the GND and RST pins to serve as a reset button Other boards in our 32U4 fami...

Page 93: ... either the Port menu is grayed out or no ports in it are selected 6 Click the Upload button The Arduino IDE will compile your sketch and start uploading it 7 As soon as the large status bar near the bottom of the IDE says Uploading reset the board twice to get into bootloader mode The Arduino IDE will stay in the uploading phase for 10 seconds waiting for a new serial port to appear Once the seri...

Page 94: ...e quickly look at the list of serial ports provided by your operating system in order to determine what port the bootloader is assigned to 9 Reset the board twice to get the board into bootloader mode again While the board is in bootloader mode quickly select the serial port of the bootloader in the Arduino IDE The port can be selected in the Port sub menu under Tools 10 In the Arduino IDE click t...

Page 95: ...go into bootloader mode You should see the yellow LED fading in and out when the AVR is in bootloader mode While it is in bootloader mode quickly look at the list of serial ports provided by your operating system in order to determine what port the bootloader is assigned to 4 Type the following command in your terminal and replace COM4 with the name of the bootloader s serial port but do not press...

Page 96: ... libc this page documents the standard library of functions that you can use with GNU C and C compilers for the AVR Balboa 32U4 Arduino library https github com pololu balboa 32u4 arduino library Balboa 32U4 library documentation http pololu github io balboa 32u4 arduino library LUFA the Lightweight USB Framework for AVRs http www fourwalledcubicle com LUFA php WinAVR http winavr sourceforge net A...

Page 97: ...w pololu com file 0J771 tps2113a pdf 1MB pdf Finally we would like to hear your comments and questions on the Pololu Robotics Forum https forum pololu com Pololu Balboa 32U4 Balancing Robot User s Guide 2001 2019 Pololu Corporation 11 Related resources Page 97 of 97 ...

Reviews: