Orangutan Mega168 LCD output

I have the Orangutan Mega168 pololu.com/catalog/product/225
I’m using the following code to have the LCD output “Hello!” and the red LED blink. [code]// F_CPU tells util/delay.h our clock frequency

//#define F_CPU 8000000UL	// Orangutan frequency (8MHz)
#define F_CPU 20000000UL	// Baby Orangutan frequency (20MHz)
#include <avr/io.h>
#include <util/delay.h>
#include <util/delay.h>
#include <stdio.h>

void delayms( uint16_t millis ) {
	while ( millis ) {
		_delay_ms( 1 );
		millis--;
	}
}
int main( void ) {
	DDRD |= 1 << PD1;			// set LED pin PD1 to output
	while ( 1 ) {
		PORTD &= ~( 1 << PD1 );	// LED off
		delayms( 100 );			// delay 100 ms
		PORTD |= 1 << PD1; 		// LED on
		delayms( 900 );			// delay 900 ms
    void lcd_init_printf();
	printf("Hello!");
	}
	return 0;
}

The LED blinks as it should. But I cannot get an output from the LCD. I’d appreciate help in understanding why. Thank you.

Try removing the “void” from void lcd_init_printf();

Mike

You’re using the original Orangutan, which is not compatible with the Pololu AVR Library, so you won’t have any success using lcd_init_printf (unless you’re using some other library I don’t know about that defines lcd_init_printf).

You could try using Orangutan-lib instead, but note that this library was not created by and is not maintained by Pololu.

Alternatively, you could read the source code of the Pololu AVR Library LCD code (found in OrangutanLCD.cpp and OrangutanLCD.h) and adapt it to work on the original Orangutan. Probably all you would need to do is change the pin definitions in OrangutanLCD.h. But this would probably be a challenge for you because that code is written in C++ and you seem new to C/C++.

–David

Thank you very much for your messages.

I forgot to add in my first message that when I went to compile and run the program I didn’t generate errors and so I was confused as to why I couldn’t see anything on the LCD. It sounds like even if the program compiles without errors it still may not fully run.

I am new to programming and had planned to use the Pololu AVR library as a starting point to communicate with the Mega168. After I made the purchase I realized that the AVR library isn’t compatible with the Mega168.

I know this is a general question, but I would appreciate some advice as to whether this is the best microcontroller for me to be using. The functions I need to be able to do are:

  1. read an analog input voltage
  2. turn a motor on/off based on the voltage reading
  3. open and close 6 micro-valves based on the voltage reading

I’ve used Stamp microcontrollers but haven’t found one that can directly read analog.
I’m not proficient in Stamp programming either but it seems the support libraries for Stamps are fairly extensive and there exists complete code in the libraries that I can copy and paste and have them run.

I would appreciate advice as to whether I should maybe switch microcontroller platforms to something that is a little more user friendly, even if it’s another Pololu, or maybe an Arduino. Thank you again. I really appreciate your help.

The program fully ran, it just didn’t behave as you expected because you didn’t initialize printf correctly, so it didn’t do the desired thing with the input string you gave it. You didn’t actually call lcd_init_printf() (by putting the “void” before it you were just declaring it, not calling it), and even if you had it would not have worked because you were trying to use a library that does not support the product you purchased. In general, there are many ways that a C program could fail to behave as expected even if it compiles without errors.

The Pololu AVR C/C++ Library is not compatible with the Orangutan Robot Controller mega168 but it IS compatible with many of our other Orangutans that are based on the AVR ATmega168 processor. The list of devices supported by the library is available in the intro of the Pololu AVR C/C++ Library User’s Guide.

[quote]I know this is a general question, but I would appreciate some advice as to whether this is the best microcontroller for me to be using. The functions I need to be able to do are:

  1. read an analog input voltage
  2. turn a motor on/off based on the voltage reading
  3. open and close 6 micro-valves based on the voltage reading
    [/quote]

What mechanism do you plan on using to open and close a micro-valve?

–David

Hello.

You really should consider at least trying Orangutan-Lib, which David linked to in his original post. It contains functions for driving the motors, writing to the LCD, and reading analog voltages, and it works with the Orangutan mega168. If after trying it you find you want something else, then I’d consider going with one of our newer Orangutans (such as the Orangutan SV or Baby Orangutan B) and the Pololu AVR library.

I can’t help you with opening microvalves without knowing details about the valves and their interface.

- Ben

Thank you for the input. I’ll definitely try out the “Orangutan-Lib” and hopefully be able to make some headway.

For the micro-valves, I’m looking into something similar to Micro-Miniature solenoid valves from ASCO. I’m not sure yet whether these specific ones will work for my application and am still researching the options.

Thank you again for all of the input.

The AVR I/O pins can generally source/sink up to 40 mA, so how you control your valves really depends on how much current it takes to control them. If they require more than can be supplied with an I/O line, you will need to use external components such as MOSFETs to deliver power to the valves.

- Ben

Ben, thank you for the I/O pin information, I didn’t consider the current limitation of the pins. This will really help as I’m researching valve options.

Thank you for pointing out the Orangutan-Lib. It’s been a fantastic resource to help me get started using my Orangutan.

I have a follow-up question related to ADC voltage inputs for the Orangutan Mega168.
I am trying to generate a simple voltage input using a 3V battery hooked up to ADC6. I am hooking up the battery with positive side to “signal” and negative to “ground”. The microcontroller behaves erradically when I try to do this. Is this expected?

Thank you again for all the help.

When making a connection you expect to be within spec, erratic behavior from the microcontroller is never the expected outcome! Can you be more specific about the nature of this erratic behavior? Are you sure you’re connecting this battery right?

If you want an easy way to test your ADC line, try alternately connecting it to the +5V bus on your Orangutan and ground while displaying the measured voltage on the LCD. You could also set up a voltage divider between VCC and ground using two resistors if you want to try measuring an intermediate voltage.

- Ben

Hello,

I thought I should mention that if you connect the 3V battery to the ADC input when the Orangutan’s power is off, you could definitely get “erratic” behavior. In general, any microcontroller connected to a voltage higher than its VCC will draw power from that connection, and 3V might be just enough to turn the Orangutan on.

-Paul

I got it to work! The LCD is displaying the voltage from the battery. Thank you again. I really appreciate all the help.

Hi. I’m having trouble understanding the I/O pins for my Orangutan Mega 168. I’m using the schematic from the Pololu sit: pololu.com/file/0J24/org01a_ … _start.pdf

I would like to use one of the pin sets as a Digital Output to simply turn a motor on then off. To protect the microcontroller, it was suggested to connect to the pin-set that uses the LB1836 H-Bridge. From the schematic, does that mean to use PB1, PD5, PB2, PD6? I don’t see where those are located on the pin-out.

Also, I have a general question about the picture showing the pin-out description. Could you please tell me what pins PB3, PB4, and PB5 are referred to?

Thank you very much for your help.
Lmm

Hi. I think I figured out the answer to my previous post. There are 2 motor ports, I think they’re PD5/PD6 for motor control 1 and PD3/PB3 for motor control 2. These are the ones I can use as digital outputs for motor control.

Lmm

The motor driver IC is already connected to the microcontroller I/O lines on the board; these I/O pins are not brought out to headers and you do not need to route them anywhere yourself. I recommend you use the Orangutan-Lib motor control functions. You’re already using Orangutan-Lib for the LCD and I think this will be much easier than trying to implement it yourself.

PB3, PB4, and PB5 are the I/O lines connected to the three user pushbuttons (see the schematic).

- Ben