As an Amazon Associate we earn from qualifying purchases.
Pinguino is an open-source platform that lets you program PIC microcontrollers using a simple, Arduino-style syntax. If you have written an Arduino sketch before, the setup() and loop() structure will look familiar. This article walks through three basic examples for the PIC18F4550 with Pinguino: blinking an LED, producing a PWM signal and printing text on a 16×2 LCD. A Proteus simulation video is included so you can see the results without hardware.
Why use Pinguino with the PIC18F4550?
The PIC18F4550 is a popular 8-bit microcontroller with built-in USB support, which is one reason it is common on Pinguino boards. Pinguino hides most of the register-level setup, so you can write pinMode(), digitalWrite() and analogWrite() instead of configuring registers by hand. If you want more background on the chip itself, see our overview of the PIC18F4550 microcontroller.
This approach suits beginners and quick prototypes. If you later need exact control over timing or peripherals, you can move to a C compiler and work with the registers directly.
What you need
- A PIC18F4550 or a Pinguino board based on it
- The Pinguino IDE installed on your computer
- An LED and a suitable resistor (or the on-board user LED)
- A 16×2 character LCD (HD44780 compatible) for the LCD example
- Proteus, if you want to follow the simulation
Pin numbers in Pinguino refer to the board’s own numbering, not the physical pin numbers of the chip. Always check the pin map for your board before wiring anything.
SIMULATION IN PROTEUS
The video below shows these examples running in a Proteus simulation. In general, you compile the sketch in the Pinguino IDE, then load the resulting HEX file into the PIC18F4550 component in Proteus. Simulating first lets you check your logic and wiring before you build the circuit.
LED BLINKING
Blinking an LED is the usual first test. The sketch sets the LED pin as an output in setup(), then switches it on and off in loop() with a short delay between each change. USERLED is a name Pinguino defines for the board’s built-in LED. You can replace it with a pin number if you wired an external LED.
void setup()
{
// initialize the digital pin USERLED as an output.
pinMode(USERLED, OUTPUT);
}
void loop()
{
digitalWrite(USERLED, HIGH);
delay(50); // wait for 50ms
digitalWrite(USERLED, LOW);
delay(50); // wait for 50ms
}
How it works
pinMode(USERLED, OUTPUT)configures the pin to drive the LED.digitalWrite(..., HIGH)turns the output on, andLOWturns it off.delay(50)pauses for 50 milliseconds.
A 50 ms delay makes the LED flash very quickly, so it may look like it is just dimly lit. Try delay(500) if you want a clearly visible blink.
PWM
Pulse width modulation (PWM) switches a pin on and off rapidly and changes the share of time it stays on. It is commonly used to dim an LED or control motor speed. In Pinguino you create it with analogWrite() on a pin that supports PWM.
void setup()
{
pinMode(12, OUTPUT);
}
void loop()
{
analogWrite(12,100);
delay(20); // wait for 20ms
analogWrite(12,255);
delay(20); // wait for 20ms
analogWrite(12,512);
delay(20); // wait for 20ms
}
Things to check
- Pin choice: Only certain pins can output PWM. Pin 12 is used in this example, so confirm it supports PWM on your board.
- Value range: On Arduino,
analogWrite()takes values from 0 to 255. Pinguino’s PIC18 PWM can use a higher resolution, which is why a value such as 512 is accepted here. Check the reference for your Pinguino version to confirm the maximum value. - Timing: The original comments said 50 ms, but the code uses
delay(20), so the comments above now say 20 ms. A 20 ms step is quick, so the change in brightness may be hard to see. Use longer delays to watch each level.
LCD
A 16×2 LCD shows two rows of 16 characters. Pinguino’s LCD library works in 4-bit mode, which needs only a few pins: RS, E and the four data lines D4 to D7. The lcd.pins() call tells the library which Pinguino pins are connected to which LCD pins.
void setup()
{
//LCDPINS----- RS -PIN5 E -PIN4 D4 -PIN3 D5 -PIN2 D6 -PIN1 D7 -PIN0
lcd.pins(5, 4, 3, 2, 1, 0, 0, 0, 0, 0); // RS, E, D4 ~ D7, unused pins set to 0
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.clear();//CLEAR DATA IN LCD
lcd.print("Hello, World!"); // Print a message to the LCD.
lcd.setCursor(3, 1); //COLUMN NO.,ROW NO.
lcd.print("EMERGING "); // Print a message to the LCD.
lcd.write('a'); //single char
int a=12;
lcd.printf("%d",a);
//lcd.noDisplay(); // Turn off the display:
//lcd.display(); // Turn on the display:
}
void loop()
{
}
What each part does
lcd.pins()maps RS to pin 5, E to pin 4, and D4 to D7 to pins 3, 2, 1 and 0.lcd.begin(16, 2)sets the display size to 16 columns and 2 rows.lcd.clear()wipes anything already on the screen.lcd.print()writes text, andlcd.write('a')writes a single character.lcd.setCursor(3, 1)moves to column 3 on the second row (counting from 0).lcd.printf("%d", a)prints the number stored ina.
Because the text is printed only once, the code sits in setup() and loop() stays empty. If you want values that change, such as a sensor reading or a clock, move the printing into loop(). For a working example of that, see how to read a DS1307 real-time clock with an LCD or send the time through a serial link using the DS1307 over UART.
Troubleshooting tips
- LCD shows nothing: Check the contrast pin (V0) and the power and ground connections first, then the data pin order.
- Garbled characters: Usually a wiring mix-up on D4 to D7, or the pin order in
lcd.pins()does not match your circuit. - LED does not blink: Make sure the pin is set as an output and the LED polarity and resistor are correct.
- Simulation does not run: Confirm the HEX file is loaded into the microcontroller and the clock frequency in Proteus matches your board settings.
FAQ
Is Pinguino the same as Arduino?
No. Pinguino is a separate project built around PIC microcontrollers. It uses a similar syntax and functions, but the libraries, pin numbering and some behavior differ, so Arduino code may need small changes.
Can I use the same code on other PIC chips?
Often yes, but pin numbers and PWM-capable pins vary by board and chip. Check the pin map for your board and adjust the pin numbers.
Why does the LED blink so fast that I can barely see it?
A 50 ms delay produces a very quick flash. Increase the value in delay() to 500 or more for a visible blink.
Do I need real hardware to try these examples?
No. You can run them in a Proteus simulation by loading the compiled HEX file, as shown in the video above. Testing on real hardware is still a good final check.