AVRSH: A Command Interpreter Shell for Arduino/AVR.

AVRSH: A Command Interpreter Shell for Arduino/AVR.
Ever wanted to be "logged in" to your AVR microcontroller? Ever thought it would be cool to "cat" a register to see its contents? Have you always wanted a way to power up and power down individual peripheral sub-systems of your AVR or Arduino in *real time* ? Me, too, so I wrote the AVR Shell, a UNIX-like shell.



It's UNIX-like because it's reminiscent of the shell account you went out and bought to run your irc nick collision bots on, as well as having a command or two in common. It also has a filesystem that resembles UNIX extfs, using an external EEPROM, but that's become a project unto itself so I'll be releasing that module separately under a different instructable when it's production-ready.

Here's a list of the things you can currently do with the AVR Shell:
  • Read all your Data Direction Registers (DDRn), ports, and pins in real-time
  • Write to all your DDRn's, ports, and pins to turn on motors, LED's, or read sensors in real-time
  • List all known registers on the system
  • Create and store values in user-defined variables backed up by EEPROM.
  • Create a root password and authenticate against it (used for telnet access)
  • Read the configured CPU clock speed
  • Change your CPU clock speed by setting a prescaler
  • Start and stop 16-bit timers for timing of various things
  • Power up and/or power down peripheral sub-systems: Analog to Digital Converters (ADC), Serial Peripheral Interface (SPI), Two-wire Interface (TWI/I2C), UART/USART. Useful for when you want to reduce power consumption of the microcontroller or to enable certain functions.
  • Written in C++ with reusable objects.

This instructable will walk through the installation, use, and customization of avrsh.
 
Remove these adsRemove these ads by Signing Up
 

Step 1What You'll Need

What You\
This instructable doesn't require much except that you:

  • Have an Arduino or ATmega328P. Other AVR's could work, but you may need to modify the code to list any registers that are unique to your MCU. The names only need to match what is listed in the <avr/io*.h> header file unique to your MCU. Many of the register names are the same between AVRs, so your mileage may vary when porting.
  • Have a way to connect to the serial USART of your Arduino/AVR. The system has been tested most extensively with the AVR Terminal, a Windows app that makes a serial connection via your USB or COM port. Works with Arduinos using the USB connection and any AVR using the USB-BUB from Moderndevice.com. Other terminal options include: Putty, minicom (Linux and FreeBSD), screen (Linux/FreeBSD), Hyperterminal, Teraterm. I've found putty and teraterm send some garbage when connecting so your first command may be garbled.
  • Have the AVR Shell firmware installed and running, which you can download from these pages, or always get the latest version at BattleDroids.net.

To install the AVR Terminal, just unpack it and run it. To install the AVR Shell firmware, download it and either directly upload the hex file and connect your serial terminal at 9600 baud, or compile it yourself with "make" and then "make program" to upload the hex. Note, you may need to change the AVRDUDE settings to reflect your COM port.

Note: The PROGMEM attribute is broken in the current AVR GCC implementation for C++ and this is a known bug. If you compile it, expect to get many warning messages saying "warning: only initialized variables can be placed into program memory area." Besides being annoying to see, this warning is harmless. As C++ on the embedded platform isn't high on the AVR GCC priorities list, it is unknown when this will be fixed. If you check out the code, you will see where I have made work arounds to reduce this warning by implementing my own attribute statements.

Pretty simple. Download and install anything that you might need to then flip the page and let's get crackin'.
« Previous StepDownload PDFView All StepsNext Step »
26 comments
Nov 2, 2011. 4:35 PMAnrax says:
little issue here not sure if its me or just the regular look in c but it wont compile at all in avr studio 5 .. been siting an working away the errors buts an very long list of them .....

so question is what compiler was used and what platform of c as it really don't want to be nice to me ..
Nov 5, 2011. 3:28 AMAnrax says:
nice :)

hopefully i will learn from it
May 31, 2011. 10:00 PMdoctorwho8 says:
This is truly amazing. But one question comes to mind. How'd I go about sending the resulting HEX file to the Arduino? Does it use one of the tools that're otherwise popular for the hardware platform?
Feb 10, 2011. 3:45 PMrasyoung says:
Sweeet!
Nov 16, 2010. 6:02 AMrf_ says:
Thanks for sharing your project!

I like it, max Kudos!

rf_
Mar 16, 2010. 10:35 AMDemonSpawn says:
 Can you view the code on the avr? thats what im looking for...
Feb 11, 2010. 5:31 AMmathman47 says:
Nice job.  How long did it take to write this (the code, not the Instructable)?  Maybe someday I'll know enough to use this!
Jan 11, 2010. 7:15 PMLeesam says:
Would pins 2 and 3 be used for RX and TX for this? I loaded the .hex on my Atmega168 (Avrdude verified it after and looked ok) and setup a Bus Pirate V3 as:
Uart 9600
no parity
1 stop bit 
Receive polarity idle 0
Output type normal (high=3.3volts, low=ground)

I was trying to use it as a Uart bridge which makes the bus pirate act as a regular RS232 usb adapter. When i connect i get nothing but 0xFF over and over.

Any ideas?
Jan 12, 2010. 8:15 AMLeesam says:
I think i saw F_CPU defined as 16Mhz in one of the source files. I just remembered that my Atmega168 was fresh and not set to use the 16Mhz crystal yet...

That's probably whats messing with mine, i'll fix it and post reply if everything works out.
Sep 18, 2009. 8:04 AMdcuartielles says:
dude, I love this one ... really really nice, we like!
Sep 17, 2009. 8:30 AMzingberra says:
I guess you have seen bitlash? http://bitlash.net
Sep 17, 2009. 12:51 AMtrialex says:
Congrats - this is not only a unique and powerful project, but also one of the best written Instructables. Kudos.
Sep 16, 2009. 10:11 PMXiver says:
Excellent. Thanks for taking the time to toss it out to us.
Sep 13, 2009. 12:49 AMjlafay says:
Thank you thank you thank you!! This is going to be great for debugging my arduino projects. Many more thanks to you nevdull.
Sep 9, 2009. 10:47 PMOrigin says:
This is amazing! What a great way to poke around at the more low-level stuff of the AVR, without sitting through a write/upload/run loop. I can't wait to try this!

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
57
Followers
20
Author:nevdull(The Bold Scientist)
Gian is a microbial biochemist and computer scientist by education and is an avid retro-computer/microcontroller geek and wishes this hobby could be self-sustaining.. He has a collection of 8-bit mic...
more »