I thought it might be useful to share my mistakes with others to help new people getting starting with microcrontrollers and to help troubleshooting some common bits of hardware.
To start with all circuits need:
a microcontroller - I'll assume it's a PIC
power - I'll assume batteries but you can use a wall adaptor
a means of programming the controller - I'll assume ISCP
Rookie mistakes that I have made in the past (and still make)
You have + / - (Vdd / Vss) the wrong way around
Something else is not wired up correctly, or a wire has popped out of your breadboard
If you have MCLREN enabled, if the pin is not pulled high the PIC may be held in reset
Your PIC didn't program correctly, did you connect the ISCP cable the right way around? (normally you will get an error when programming if this is the case)
Are any component legs touching? This can stop crystal oscillators running and stop I2C signals getting through
Internal ocscillator not running. Some PICs require you to explicitly say to use the internal oscialltor and there are different ways of doing this including:
#config OSC=INTOSC '16F1825, 16F1847
#config OSC=INTRC_OSC_NOCLKOUT '16F676, although OSC=INTRC will also work
#config OSC=INTRC_OSC_RB4EN '16F505
#config RSTOSC=HFINT32 '16F18326
Last edit: Peter 2016-09-24
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First of all - start simple. If you can't get the most basic of program to work then something complex won't work either and it will be much harder to find the problem.
This circuit is the "Hello World" of microcontrollers and it simply flashes an LED to prove that it has been programmed and that it is running. If this doesn't work then check everyhting in the first post plus check whether the LED is the wrong way around.
Schematic, breadboard layout and source code are attached. Video of the circuit here: https://youtu.be/59GFhE7iwy8
Next, you'll usually want to the microcontroller to tell you something - either the value of a sensor or some debugging information. One basic way to do this is with an LCD display.
The 'typical' LCD device has a parallel interface with 8 data bits, plus control lines and come in 1x8, 2x8, 2x16 or 4x20 varieties plus some others. This is too many connections to use on a 14 pin PIC (unless you resuse the ICSP connections) however you can control the display using only 4 data bits which is what I've used in this example.
These displays require a potentiometer to control the contrast which makes sure the text shows up on the display. The setting on the potentiometer will change depending on the voltage used to supply the LCD.
If this isn't working, check the following:
Are there any loose wires on the breadboard. This is a congested layout so it's easy to knock a wire loose, expecially when attaching the programmer
Is the potentiometer set correctly?
Have you got any connections mismatched? When writing this example I had PORTC.3 and PORTC.4 connected the wrong way around, and I had forgotten the connection from D4 on the LCD.
Does the LCD backlight come on? The backlight is just an LED but you often need it to be on in order to see the the text.
Schematic, breadboard layout and source code are attached. Video of the circuit here: https://youtu.be/cvx8Uuy5z8s
I2C is a way to communicate between the PIC and other devices such as sensors and displays. It is a bus system, so you can keep adding devices to the bus and access them using their unique ID.
I2C displays such as the SSD1306 are also available and only require 2 connections (plus a Vdd and Vss) compared to the large number needed for a parallel LCD.
The example below uses I2C to communicate with the GLCD. It requires a PIC with a lot of RAM (>1k) due to the display unless you use a cut down version of the driver, however it will work at clock speeds down to 4MHz - albeit very slowly.
If this doesn't work check:
Have you got the pullup resistors (from SDA to Vcc and SCL to Vcc)?
Are the legs of the resistors touching?
If the text appears on the display then disappears then GND on the display is not connected properly
I thought it might be useful to share my mistakes with others to help new people getting starting with microcrontrollers and to help troubleshooting some common bits of hardware.
To start with all circuits need:
Rookie mistakes that I have made in the past (and still make)
Last edit: Peter 2016-09-24
First of all - start simple. If you can't get the most basic of program to work then something complex won't work either and it will be much harder to find the problem.
This circuit is the "Hello World" of microcontrollers and it simply flashes an LED to prove that it has been programmed and that it is running. If this doesn't work then check everyhting in the first post plus check whether the LED is the wrong way around.
Schematic, breadboard layout and source code are attached. Video of the circuit here: https://youtu.be/59GFhE7iwy8
Last edit: Peter 2016-09-24
Next, you'll usually want to the microcontroller to tell you something - either the value of a sensor or some debugging information. One basic way to do this is with an LCD display.
This is a good basic overview of these displays: https://learn.adafruit.com/character-lcds/wiring-a-character-lcd
The 'typical' LCD device has a parallel interface with 8 data bits, plus control lines and come in 1x8, 2x8, 2x16 or 4x20 varieties plus some others. This is too many connections to use on a 14 pin PIC (unless you resuse the ICSP connections) however you can control the display using only 4 data bits which is what I've used in this example.
These displays require a potentiometer to control the contrast which makes sure the text shows up on the display. The setting on the potentiometer will change depending on the voltage used to supply the LCD.
If this isn't working, check the following:
Schematic, breadboard layout and source code are attached. Video of the circuit here: https://youtu.be/cvx8Uuy5z8s
Last edit: Peter 2016-09-24
I2C is a way to communicate between the PIC and other devices such as sensors and displays. It is a bus system, so you can keep adding devices to the bus and access them using their unique ID.
I2C displays such as the SSD1306 are also available and only require 2 connections (plus a Vdd and Vss) compared to the large number needed for a parallel LCD.
The example below uses I2C to communicate with the GLCD. It requires a PIC with a lot of RAM (>1k) due to the display unless you use a cut down version of the driver, however it will work at clock speeds down to 4MHz - albeit very slowly.
If this doesn't work check:
Last edit: Peter 2016-09-24