NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Basic Electronics » Automated programming mode?

August 05, 2013
by Twarter369
Twarter369's Avatar

Hello again everyone. After a break from toying with the NK, I am back. I would like to interface it with my Raspberry Pi using the USB->Serial cord and one of the RPi's GPIO pins.

I want to use the GPIO pin and a NPN transistor to control the 168's programming mode.

It seems pretty straight forward in my head, but are there any special considerations I have missed? The RPi logical 1 is a 3.3v signal but since I am only using it to pull a pin to GND I thought that would be enough to control a transistor. Does all of this sound correct?

Also, if it is of interest to anyone, I will be programming the chip On the Fly using Python and a LAMP stack.

August 05, 2013
by pcbolt
pcbolt's Avatar

Hi Twarter -

The 168 can be used at 3.3 volts. Some have had trouble using 3.3v and having a 14 Mhz crystal but I have not run into this problem as yet. If you use 5 volts to power the 168, it understands logic 1 to be anything higher that 0.6 * Vcc or 3.0 volts. So it looks like you may not need an external NPN. I don't know if you'll need the USB cable either. If you are using GPIO pins on the RPi, you should be able to program using the SPI lines on the 168. The 168 user guide explains the details you'll need to upload to the flash memory so it is worth the read.

Good luck...sounds like a fun project and I hope you keep us updated on your progress.

August 05, 2013
by Twarter369
Twarter369's Avatar

Thanks PCBolt. The USB->Serial is also going to be used in non-programming mode for serial control. I know I could use the GPIO RX/TX to accomplish the same but the USB seemed easier. At least for me to grasp.

I thought of the NPN transistor because in the initial NK setup there is a SPST switch that pulls pin 14 to GND. My thought was: If I replace that with a transistor then toggling the pin on the pi should create the same effect as throwing the switch.

I will definitely look back over the data sheet for the SPI bus. I have to do that anyway for interrupts :D Thanks for the suggestion and I will definitely post some of my code ideas!

August 05, 2013
by JimFrederickson
JimFrederickson's Avatar

Hi Twarter,

"I would like to interface it with my Raspberry Pi using the USB->Serial cord and one of the RPi's GPIO pins."

and

"I want to use the GPIO pin and a NPN transistor to control the 168's programming mode."

So are you creating a program in the AVR '168 that will monitor that pin and enter some programming mode?

Or are you intending to replace the switch used to enter programming mode in the standard Nerdkit Scheme?

If it is the latter, then that condition is only checked, unless your program will be setup to check it, when the AVR is rebooted.

Maybe you will need 2 pins? (One for "Reset", or even "Power", and the other for the "programming mode".)

It sounded to me that you just wanted to "automate the Nerdkit Programming Scheme" so that it could all be handled from the Raspberry Pi...

Or maybe I am missing something...

August 06, 2013
by Twarter369
Twarter369's Avatar

Hi Jim, I plan to use it to automate the re-writeing of the chip the same way as the initial setup. For instance, I will have a button labeled Traffic light that will automatically re-write the chip with the trafficlight code and reboot the chip in operating mode.

From what you're saying it sounds correct that I would need a pin to toggle the power to the 168, and another to control the programming mode switch. It sounds reasonable that i'd need to pause the pi to allow the reboot of the 168. Is there a relatively stable boot time?

So on the Pi the operation would flow like this: Switch power to 168 off > Switch programming transistor to logical 1 (grounding pin)> Switch power to 168 on > Python calls make on the project and logs error or success > Power off the 168 > Switch programming mode off > If successful write turn power to 168 back on resuming normal operating mode.

The idea is that this will allow me to tweak the code on the chip without needing to physically connect to the device. So long as I can connect to my Pi I will be able to program and test the chip while it is still in the project I am working on.

August 10, 2013
by JimFrederickson
JimFrederickson's Avatar

That sound interesting Twarter.

The boot time is pretty "negligible"...

I would wait 2 seconds.

I don't have a definite number as to how long booting takes, but I think you can for- all-intents-and-purposes consider it instantaneous.

If you are going to control power to the AVR Chip then you will also be needing a transistor. You are not going to be able to control it directly.

Personally, I would consider purchasing a "Level Shifter/converter" to go in between.

Mostly just to protect the GPIO's on the Pi. (There are also alot of Raspberry Pi I/O modules, but most of those end up costing as close to as much or more than the Raspberry Pi!)

It is one thing to blow a $3 chip because something is miss-wired it is quite another to blow a $7 chip on a $40 board...

Just something to think about.

August 10, 2013
by Twarter369
Twarter369's Avatar

So, I have made some progress on this project. I have my Pi wired up to the 168 using the included USB cable. I also have a PNP transistor to control the power (2n3904 I believe)to toggle the power. Finally, I have an NPN transistor (2n2222) to pull the pin to GND. I will be testing writing to the chip tonight.

Thanks again everyone. I will post my results and the Py bits once they are working!

April 07, 2014
by scootergarrett
scootergarrett's Avatar

I’m trying to send data from the raspberry pi GPIO UART pint to the nerdkit. I have a program that sends numbers out from the nerdkits but I’m having trouble reading it. I would like to do it in C at some point but python is fine, does anyone have any experience with this.

April 08, 2014
by Rick_S
Rick_S's Avatar

You might check Adafruit, they have a tutorial on freeing up the UART on the raspberry pi for other use. (By default it is setup to be a serial console for login) If you go to Adafruit's learning section, it will explain the steps needed to do it. I think they even have examples for reading serial data from a GPS module which you may find useful for reading from your microcontroller.

Rick

Post a Reply

Please log in to post a reply.

Did you know that you can build a giant scrolling LED array with our microcontroller kit? Learn more...