Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

My new tool to program the ATTiny85 for servo use

5924 views
3 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
My new tool to program the ATTiny85 for servo use
Posted by rrinker on Tuesday, November 15, 2016 7:11 PM

(and anything else I might want to use a neat little 8 pin micro with 5 I/O pins for)

Not an original design, this is the full featured version of the Arduino ISP circuit. The basic ones just connects the pins to the ATTiny to be programmed, and with an Uno as the Arduino you need the 10uF capacitor across ground and reset. The deluxe version adds the 3 LEDs on the right. Yellow is heartbeat, red indicates an error, and the green flashes while programming. The clear LED below the socket is actually a blue one, set up so I can install a 'blink' sketch using Arduino pin 3 (actual pin 2 on the chip) and test each one right away. This is built as a shield as you can see. The ATTiny to be programmed (it works with all the 8 pin versions, not just the 85, the 85 just has the most memory) goes in the socket, pin 1 to the lower left where the red wire goes in - so notch if the chip has one to the left, towards the USB connector on the Uno underneath. The Uno runs the ArduinoISP sketch (it comes with the IDE, under File,Examples). You then open the sketch you want to load on the ATTiny, select the approriate chip, and select Arduino as ISP for the programmer under Tools,Programmer. You also need to add the additional 'board' files to get the options for the ATTiny line to show up, those are not built in to the IDE. 

 There's no difference in coding, it's the same as any Arduino, you just only have 5 I/O lines to work with, of which 3 can be used as analog inputs. I'm using them initially to make servo controllers, each one will take 2 inputs to toggle 2 servos, the 5th pin will be an input with a jumper that when set will move both servos to center for easy installation. 

                           --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2010
  • From: Chi-Town
  • 7,712 posts
Posted by zstripe on Wednesday, November 16, 2016 8:31 AM

Randy,

Interesting......It reminds Me of the circuit design console I have from My Tech school days (Bell & Howell) for testing and creating different circuits/amplyfiers....but in miniature. I just got old too fast for all the advancements in electronic's now a days.

Take Care! Big Smile

Frank

  • Member since
    November 2016
  • 4 posts
Posted by Erik84750 on Sunday, November 20, 2016 7:04 PM

Very interesting! Can you provide the schematic and an example sketch for a servo function decoder where a Attiny commands servo's? I am interested in learning how you program this Attiny to work as a function decoder (adressing, CV's, servo performance,..).

Thks,

Erik

 

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Monday, November 21, 2016 4:38 PM

Here's my schematic - not finalized, there are some adjustments to be made.

http://www.readingeastpenn.com/images/ServoController.pdf

Some sites that have info on the code used for a servo:

http://projectsfromtech.blogspot.com/2013/03/attiny85-servo-softwareservo-library.html

http://hackaday.com/2011/09/25/attiny-hacks-attiny4585-servo-library/

 

 I'm not doing this as a DCC accessory decoder, so you'd have to find someone's Arduino NMRA DCC library and also use one of the pins as the connection to the track to read the DCC signal. My code is just based on the examples from the Software Servo library but instead of continuous sweep they only toggle the servo in inputs. I'm just running them from end to end, less a bit of headroom (so say 5 degrees at one extreme and 175 at the other) because the servo mounts handle plenty of overtravel, they are meant to go from end to end, not just a short motion enough to move the throwbar. This forms a bit of an over center spring so I am also cutting the signal to the servo once the movement stops to prevent noise and save power. I can bend the piano wire before it forces the servo to move, so i anticipate no problems holding the turnout in position. I have a stack of old Tam Valley/Motrak mounts (resin castings) and I plan to use the new laser cut wood ones from Tam Valley going forward.

 My code is pretty simple, there's no customization. The only thing I allowed is that jumper in the circuit, on one side it will force both servos to center, on the other it allows normal operation. And speed adjustment would have to be done by modifying the code - and even on the Tam Valley drivers I used on the last layout, I only ever just set the speed and never played with that again, so I don;t see any need for it. Oh, and I do have it write the last position to the EEPROM after every move - with a nested loop routine to write all 512K of EEPROM so it doesn;t hit the 10,000 write life cycle specified in the data sheet. By distributing the writes, I calculated that if you flip the switch 4 times per minute, for 4 hours straight, 4 days a week, it will be 28 YEARS before any memory location hits 10K writes. I think that should be sufficient...

                         --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!