PICAXE Microcontroller with Parallax Serial LCD Display

Parallax Serial LCDDo you want to add an LCD display to your PICAXE project? Do you have a limited number of output pins on your microcontroller? The Parallax Serial LCD display is a great solution!

The Parallax 2×16 serial LCD display has only 3 pins. Only one of those pins connects to the microcontroller. The other two are for power connections.

It turns out, Parallax has made it very easy to communicate with the LCD display with simple serial commands. You can test your display by using or modifying the PICAXE program I have written below.

NOTE: To use the display at the PICAXE’s default 4 Mhz, the LCD will need to be set for a 2400 baud rate and the program will change from:

setfreq m16
symbol tx = c.4
symbol baud = T9600_16

…to…

setfreq m4
symbol tx = c.4
symbol baud = T2400_

The code below will test the serial communication, the display back-lighting (if applicable), and the on-board speaker/sound controls.

I hope this proves useful to somebody! Enjoy!

RESOURCES:

' ------------
'|  LCD Test  |
' ------------

'by Alexander Hogen

'Started: 9-16-2013
'Finished: 9-16-2013

'See "Command Set" in this PDF for
'more information.
'http://www.parallax.com/sites/default/files/downloads/27979-Parallax-Serial-LCDs-Product-Guide-v3.1.pdf

setfreq m16

'9600 baud only works in 16MHz or higher

'Multiply desired millisecond (ms) timing
'by 4 to get desired result.
'i.e. "Pause 5" becomes "Pause 20"

symbol tx = c.4
symbol baud = T9600_16

pause 400

main:
serout tx, baud,(22) 'Turn display on
pause 40
gosub clearLCD
serout tx, baud,(17) 'Turn backlight on

serout tx, baud,("Hello")

pause 4000

gosub clearLCD
serout tx, baud,("LCD works great!")

gosub beeps

end

clearLCD:

serout tx, baud, (12)
pause 40
return

beeps:

serout tx, baud,(216) 'Select the 4th scale (A=440Hz)
pause 40
serout tx, baud,(210) 'Set note length to 1/16 note
pause 40

serout tx, baud,(220,221,222,223,224,225,226,227)
pause 4000

return
Rate this Post/Page

Open-source DIY Greenhouse Project


In a college class this last year, a group of us were assigned to design a system that would collect and graph environmental data from our campus greenhouse. We would take this data, graph it, and display those graphs on a public website. We’d also use current data to control the greenhouse (i.e. watering, heating, cooling…). Hopefully this information helps you if you are wanting to start your own DIY project and automate your greenhouse.

We decided to use an Arduino UNO, a PICAXE-14M2, and a desktop computer running Windows Vista. The Arduino functioned as the main interface and brain. We dedicated the PICAXE to simply reading sensors and sending that data in a continuous stream to the Arduino via a serial communication protocol.

The Arduino would format and send data to be logged to the PC, which runs MegunoLink. The Arduino would also decide, based on environmental conditions, if the heater/cooler/water should be turned on. Future groups working on the project would have to decided whether the Arduino would do this by sending a command to a dedicated microcontroller (reverse of what we did with the PICAXE being dedicated to sensors) or by directly controlling equipment in the greenhouse.

So, in essence, for this project, we figured out how to set up data logging and automation of the greenhouse environment using cheap materials and open source equipment.

In our report, we provide example code for both microcontrollers and discuss difficulties we ran into along the way. You can read this report by clicking on the PDF link below.

Final Report – COCC Greenhouse IT Group.pdf

IT Budget/Component Pricing.pdf

DATASHEETS:

 

Open-source DIY Greenhouse Project
3(60%) 1 votes

Login App – Useing External Database List

Here’s a program I wrote with the help of a friend who’s a little more familiar with Free Pascal than I am. I used Lazarus to program this. If you don’t know what Lazarus is, then you should look it up. It’s amazing.

This program will use an external list of names and passwords to grant access to whatever you want. You’d probably want to implement some sort of encryption/decryption in this system, but the basic framework of a login application is here. I had a basic text file called “doing” functioning as my database file. I also renamed the file extension from “.txt” to “.filter” just for the fun of it. Obviously you can change these to whatever you want as long as you change it in the program and recompile it.

Here’s the code:

Ext_list_Login_app_proj.zip



program Ext_list_Login_app_proj;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };

var
name:string;
real_name:string;
pass:string;
real_pass:string;

{This program is divided up into procedures just to make it a little easier for me.}

procedure login_complete;
begin
writeln();
writeln('Hey you remembered BOTH your username AND password!');
writeln('If you wanted to really do something important with this,');
writeln('than you would probably launch a program or something at this point.');
writeln('But right now, this program does nothing like that.');
writeln();
writeln();

end;

function check_pass(const name:string;const pass:string): boolean;
var
f:textfile;
s:string;
x:integer;

begin
assignfile(f, 'doing.filter');
reset(f);
try
while not eof(f) do
begin
readln(f,s);
x:=pos(':',s);
result:=(copy(s, 1, x-1)=name) and (copy(s, x+1, length(s)-x)=pass);
if result then exit;
end;
finally
closefile(f);
end;
end;

procedure login;
begin
writeln();
writeln('Enter Username:');
readln(name);
writeln();
writeln('Enter Password:');
readln(pass);

{Now that we have user input, the application will now verify that information with the correct answers}

if check_pass(name, pass)then
login_complete;
end
else
begin
writeln();
writeln('Oops. You entered the wrong username and password combination.');
writeln('Try again.');
login;

end;
end;

{"Main" program below}

begin

writeln('Welcome to the Login Application!');
writeln();

login;
writeln('Press <enter> to quit.');
readln();
end.


Rate this Post/Page

Frequency Harmonic Calculator in C++

I just came up with a little Frequency Harmonic Calculator in C++. Calculating harmonics isn’t hard, but if your doing a bunch of calculations, this might come in handy. To calculate a harmonic, simply take the fundamental frequency (F) and multiply it by an integer value (i.e. 3). So, for example, if F = 520 KHz, then the 3rd harmonic would be (Fx3) = (520×3) = 1560 KHz.

I also wrote a section of this program to calculate frequencies that have a harmonic of the frequency you enter. So if you enter 520, it will let you know that 260 KHz has a harmonic of 520 KHz. I needed something like this for a project I’m working on, so I decided to share what I came up with.

There is something funny/nice that occurs. If you enter both the value (i.e. 520) and the measurement (i.e. KHz) when it asks for the fundamental frequency, it will somehow write the frequency to the ‘freq’ variable and the measurement to the ‘unit’ variable and skip the step where I ask for the unit of measurement. All the calculations are correct and everything. I might know why this is, but I’m not sure enough to spit it out. Anyway, kinda cool.

I also put up this code here: http://pastebin.com/8y8pcVPr



#include <iostream>
#include <stdio .h>
#include <string>

using namespace std;

class calculator
{
public:

int highArray[15];
int lowArray[15];
int freq;

void harmonics(int);
void lowFreq(int);

};

void calculator::harmonics(int freq)
{

for (int i; i < = 15; i=i+1)
{
highArray[i] = freq*(i+1);
}

}

void calculator::lowFreq(int freq)
{
for (int i=0; i<=15; i=i+1)
{
lowArray[i] = freq/(i+1);
}
}

int main()
{
int freq;
string unit;

cout << "What is the fundamental frequency?\n\n";
cin >> freq;
cout < < "\nWhat unit of measure are you useing? (Hz, KHz, MHz,... )\n\n";
cin >> unit;
cout < < "\n\n";

calculator related_freqs;

related_freqs.harmonics(freq);

cout << "The harmonics of " << freq << " ";
cout << unit << " are...\n\n";

for (int i=0; i<=15; i=i+1)
{
cout << "Harmonic #"<< (i+1) << " " << related_freqs.highArray[i];
cout << " " << unit << "\n";
}

cout << "\n\n\nNow I'll calculate frequencies that have a harmonic of " << freq;
cout << " " << unit << "\n\n";

related_freqs.lowFreq(freq);

for (int i=0; i<=15; i=i+1)
{
cout << "Frequency #"<< (i+1) << " " << related_freqs.lowArray[i];
cout << " " << unit << "\n";
}

cout << "\n\n\nPress any key and hit ENTER to quit.\n";
cin >> freq;
// getchar();    // For some reason or another, this command has never worked for me. That's why I wrote the above line so that the user can actually read the data output. It's not as nice, but it works.
return (0);
}


Rate this Post/Page

Age Calculator in C++

This is my first program in C++ that truly uses object oriented programming capabilities. Some of the code is a little redundant. I wrote it this way to help me understand what is really going on when your passing data around.

I thought I’d throw the code up here for anyone who would like to use it. Here you go.

If you find an error/bug, please leave me a comment!

Age Calculator.txt



#include <iostream>
#include <stdio .h>
#include <time .h>
#include <string>

using namespace std;

class date
{
public:
int day;
int month;
int year;
int daysold;
int monthsold;
int yearsold;

//I defined two methods. The "birth" method and "age" method both accept three integer variables.
void birth(int, int, int);
void age(int, int, int);
};

void date::birth(int b_day, int b_month, int b_year)
{
// This mearly takes the birthday (DD MM YYYY) entered and writes it to the class's variables for the other method to use.

day = b_day;
month = b_month;
year = b_year;

//cout < < day << "/" << month << "/" << year << "\n";           // This was for me to test what data is really reaching those three variables.

}

void date::age(int c_day, int c_month, int c_year)
{
//This method actually does something useful! Useing both the current date and the birthdate, it will calculate "monthsold", "daysold", and "yearsold."

//NOTE: THESE ALGORYTHMS DO NOT CURRENTLY RETURN ACURATE VALUES AS THEY DO NOE ACCOUNT FOR LEAP YEARS. Hmm... mabe something to change when it's not 11:53 pm

monthsold = (((c_year*12) + c_month) - ((year*12) + month));

daysold = (monthsold*30) + day;

yearsold = monthsold/12;
}

int main()
{
// -----------------   VARIABLES   -------------------
int b_day;
int b_month;
int b_year;
int c_day;
int c_month;
int c_year;

//------------------ GET SYS TIME  -------------------

time_t tim;  //create variable of time_t
time(&tim); //pass variable tim to time function
cout << "Program initiated on " << ctime(&tim) << "\n\n"; // this translates what was returned from time() into a readable format

time (&tim);
struct tm * ptm= localtime(&tim);
c_day = ptm->tm_mday;
c_month = (ptm->tm_mon)+1;
c_year = ptm->tm_year + 1900;

//------------------ START ASKING QUESTIONS -------------------

cout < < "In what year was the subject born? (i.e. 1982)\n";
cin >> b_year;
cout < < "\nIn what month was the subject born? (i.e. 09)\n";
cin >> b_month;
cout < < "\nOn what day was the subject born? (i.e. 27)\n";
cin >> b_day;
cout < < "\n";

//------------------ VERIFY INFORMATION ------------------
//Define an object from the "date" class. I'll call my object "human."
date human;

// Send the collected data to the "birth" method
human.birth(b_day, b_month, b_year);

//Put a confirmation message up.
cout << "You said that the subject was born on " << human.month << "/" << human.day << "/" << human.year << " if I'm not mistaken.\n";

//Send current date to AGE method to run calculations
human.age(c_day, c_month, c_year);

//------------------ DISPLAY CALCULATIONS --------------------

cout << "\nOk. In case you were wondering, the subject is somewhere around\n\n";
cout << human.yearsold << " years \n\n";
cout << "...or...\n\n";
cout << human.monthsold << " months \n\n";
cout << "...or...\n\n";
cout << "aprox. " << human.daysold << " days old\n\n\n";
cout << " - - - | - - -\n\n";
cout << "Sorry, that's my best extimate.\n";

//---------------------- QUIT MAIN PROGRAM ----------------------cout << "\n Press any key and hit ENETER to close." << endl;

cin >> c_day;
//int getchar();    // For some reason or another, this command has never worked for me. That's why I wrote the above line so that the user can actually read the data output. It's not as nice, but it works.
return (0);

}

Rate this Post/Page