Basics
From Pinguino-Wiki
| Language: | English |
|---|
Contents |
Bootloader
The bootloader is a small program running inside your Pinguino's microcontroller (PIC18F or PIC32MX) which is responsible for transferring your user program from your computer to the Pinguino's microcontroller program memory and handing over the control to this program afterwards.
The bootloader is always pre-installed on commercial boards.
If you made your own board, then you must program your Pinguino (only one time) using a standard PIC programmer which supports your PIC microcontroller to install the bootloader.
About 8-bit Pinguino
There are currently 4 bootloaders but 2 are really supported (available here):
- Version 1 which can be used only on 18F2550 based Pinguinos (about 7K);
- Version 2 which can be used on both 18F2550 and 18F4550 based Pinguinos (about 7K).
- Version 3 is based on Diolan bootloader and is written in ASM (about 1.5K). Unfortunately it can not work with SDCC which does not support PIC18F Extended Instructions Set. However it works perfectly with MPLAB X.
- Version 4 is written with SDCC (>3.0.0), is less than 3K and is available for PIC18F 1xK50 (not tested), x455, x550, x6J50, x6j53 and x7j53 based Pinguinos, with Internal or External crystal, at low (not supported by the Pinguino IDE) or high speed USB.
When using version 1 you have to include the run button in your design or nothing will happen.
When using version 2, 3 or 4 the run button can be omitted because control will be handed over to the user program 5 seconds (10 seconds when using version 3) after powerup or reset.
About 32-bit bootloaders
All 32-bit bootloaders can be found here.
Uploading your program
First of all run the Pinguino IDE.
Write your user program and then regardless of the bootloader you are using, compile it.
on 8-bit Pinguino
Depending on your Pinguino design, there are two bootloader versions.
In version 1 (see above) of the bootloader:
Push the reset button on your Pinguino board. The run led should remain dark. If it is lit, you have probably short circuited the run button with a jumper.
Click on the upload button and wait for the VascoBootloader to appear. Click the 'write' button in VascoBootLoader.
You should get something like PIC found followed by XXX.hex uploaded, XXX being the filename of your user program.
Now push the run button to start your program.
When using version 2 (see above) things get a little trickier, just a little.
First click the upload button in the Pinguino IDE and wait for the Vascobootloader to appear. Now hit the reset button on your Pinguino board and wait for about 3 seconds. Click on 'write' in the VascoBootLoader.
You should get something like PIC found followed by XXX.hex uploaded, XXX being the filename of your user program.
If you get 'PIC not found !!' you have not waited long enough, just click 'write' again.
If you get 'PIC found' followed by nothing you waited too long. In this case Reset your Pinguino board, wait 3 seconds and try again.
When using version 3 and above (see above) things get simpler.
First press the reset button on your Pinguino board. The built-in led should stay on solid. You now have 5 seconds to upload your program.
Second, click the upload button in the Pinguino IDE.
That's it !
You should get something like :
Pinguino found ...
- with PIC18f26j50 (id=0x4c40)
- with USB bootloader v4.x
Writing User Application ...
xxxxxxx.hex successfully uploaded
Starting Application ...
If you get :
Pinguino not found.
Is your device connected and/or in bootloader mode ?
you may have not connected your board or you may have waited too long after pressing the reset button before uploading your program. Try again from the beginning.
on 32-bit Pinguino
Before telling the Pinguino IDE to upload your program you need to connect your board and put it in bootloader mode:
Press and hold down the user button BUT Press and release the user button RST (Reset) Release the user button BUT
You should now see the two built-in LEDs (yellow and green) flashing alternately. Now you and your Pinguino are ready to upload your program.
Once the upload is complete, the two LEDs will stop flashing and the program will start automatically.
To exit the bootloader mode without uploading a new program:-
Press and release the user button RST (Reset)
The two LEDs will stop flashing and the previously installed program will start running again.
Hello World
Step 1
- Windows
Prepare the connection to the Pinguino device by installing the driver from: http://linux.gatewaybbs.com.au/~zapper/EFIlive/USB%20Cable%20driver/
You will have a COMx connection when you plug the usb cable to the computer.
- Linux
Nothing to do.
Step 2: Write the following in the Pinguino IDE
void setup() { // put your setup code here, to run once: } void loop() { // put your main code here, to run repeatedly: CDC.println("\n\r Hello World!!!"); }
Step 3: Compile and upload the code (see above)
Step 4: Select Menu->Pinguino->Debug Mode->USB CDC And on the bottom section the port x on which the device is connected and there you go:
Hello World!!!
alternative:
- Windows
You also can use an other terminal or console such as putty to view the output. The settings are:
- Port: it depents. Normally it will be COM7. You can guess or you can check it. In Windows you can do this by right clicking on "my computer" -> manage -> device manager -> ports -> there should be a "communications port (COMx)". The x is the number of your COM port. If there is none but you have a yellow question mark in the device manager, you possible need to install the CDC driver. First download: http://ww1.microchip.com/downloads/en/AppNotes/CDC_RS232_Emulation.EXE. After you installed the package, go in the device manager to the yellow question mark, right click it and choose to manage or install the driver and point to the installed folder. (standard: C:\MCHPFSUSB\fw\Cdc\inf\win2k_winxp). This will install the driver. If it does not work, the question mark could be from an other device that needs your attention. The driver from the link normally will work from Windows 2000 till Windows 8 X64.
- Speed (Baud): 115200
- Data bits: 8
- Stop bits: 1
- Parity: None
- Flow control: XON/XOFF
- That's it
- Linux
You can use a Terminal Emulation Program such as Minicom :
sudo minicom -o -D /dev/ttyACM0
Writing programs
Init function
TODO
void setup() { pinMode(0,OUTPUT); }
Main function
TODO
void loop(void) { digitalWrite(0,HIGH); delay(500); digitalWrite(1,HIGH); delay(500); }
Interrupt function
TODO
void interrupt() { // timer 1 interrupt flag in register PIR1 if (PIR1bits.TMR1IF) { // reset interrupt flag PIR1bits.TMR1IF=0; // reverse state of pin 0 ( blink ) digitalWrite(0,digitalRead(0)^1); } }
If an interrupt service routine changes variables which are accessed by other functions these variables have to be declared volatile. See [1] (From the Documentation).

