Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Development / Re: Ansiterm: a ansi terminal library on: February 19, 2010, 02:57:37 pm
I find that terminal rather quirky in other aspects as well. However, given the number of excellent full-fledged terminal programs, I don't think it really makes sense for Arduino development to be devoted to these efforts. Rather, I just turn off the Arduino terminal and launch an ansi-compatible one when I'm using code that uses ansiterm. All macos and linux terminals are great. On windows, it's more complicated.
2  Forum 2005-2010 (read only) / Development / Re: Ansiterm: a ansi terminal library on: February 12, 2010, 07:20:58 pm
Thanks, cr0sh, I'm glad you like it. Would you put it under InterfacingWithHardware#Communication in playground?
3  Forum 2005-2010 (read only) / Development / Ansiterm: a ansi terminal library on: February 12, 2010, 03:28:28 pm
I've written a library that simplifies the use of ansi terminal escape codes. The updated version of the code resides at:
http://code.google.com/p/qrptracker/source/browse/#svn/trunk/Arduino/libraries/Ansiterm
And you'll find a video of a useful application of this library at


The files as of [timestamp=1266006177] are Ansiterm.h
Code:
/*
Ansiterm.cpp -- an Arduino library that simplifies using the ANSI terminal
control escape sequences. This allows your code to  position text exactly in the
terminal, to add colour and other effects. To use Ansiterm, an ANSI terminal must
be connected to the Arduino's serial port. The terminal built into the Arduino
IDE does not respond to the ANSI codes, but most MacOs and Linux terminals do.
In Windows, I read that Hyperterm responds to ANSI codes. Realterm responds to most
codes, but will not change the color of the foreground.

The accompanying example file illustrates the library's use.

Copyright (c) 2009 Bruce Robertson, VE9QRP. All rights reserved.

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.

This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

The latest version of this software is available at http://code.google.com/p/qrptracker/
*/

#ifndef Ansiterm_h
#define Ansiterm_h
#include "WProgram.h"

#define ESCAPE 0x1B
#define BRACE '['
#define BLACK 0
#define RED 1
#define      GREEN 2
#define YELLOW 3
#define BLUE 4
#define MAGENTA 5
#define CYAN 6
#define WHITE 7
#define BOLD_ON 1
#define BOLD_OFF 22
#define UNDERLINE_ON 4
#define UNDERLINE_OFF 24
#define ITALICS_ON 3
#define ITALICS_OFF 23
#define STRIKETHROUGH_ON 9
#define STRIKETHROUGH_OFF 29
#define INVERSE_ON 7
#define INVERSE_OFF 27
#define RESET 1
#define DEFAULT_FOREGROUND 39
#define DEFAULT_BACKGROUND 49


class Ansiterm {
      
public:
      Ansiterm();
      void home();
      void xy(int x, int y);
      void up(int x);
      void down(int x);
      void forward(int x);
      void backward(int x);
      void eraseLine();
      void eraseScreen();
      void setBackgroundColor(int color);
      void setForegroundColor(int color);
        void boldOn();
        void boldOff();
        void underlineOn();
        void underlineOff();
        void italicsOn();
        void italicsOff();
        void strikethroughOn();
        void strikethroughOff();
        void inverseOn();
        void inverseOff();
        void reset();
        void defaultBackground();
        void defaultForeground();
        void fill(int x1, int y1, int x2, int y2);
private:
      void preamble();
      void preambleAndNumberAndValue(int x, char v);
      void setAttribute(int a);
      
};
#endif

and Ansiterm.cpp
Code:
/*
Ansiterm.cpp -- an Arduino library that simplifies using the ANSI terminal
control escape sequences. This allows your code to  position text exactly in the
terminal, to add colour and other effects. To use Ansiterm, an ANSI terminal must
be connected to the Arduino's serial port. The terminal built into the Arduino
IDE does not respond to the ANSI codes, but most MacOs and Linux terminals do.
In Windows, I read that Hyperterm responds to ANSI codes. Realterm responds to most
codes, but will not change the color of the foreground.

The accompanying example file illustrates the library's use.

Copyright (c) 2009 Bruce Robertson, VE9QRP. All rights reserved.

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.

This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

The latest version of this software is available at
*/

#include "WProgram.h"
#include "Ansiterm.h"

Ansiterm::Ansiterm()
{
}


void Ansiterm::home()
{
  preamble();
  Serial.write('H');
}


void Ansiterm::xy(int x, int y)
{
  preamble();
  Serial.print(y,DEC);
  Serial.write(';');
  Serial.print(x, DEC);
  Serial.write('H');
}


void Ansiterm::up(int x)
{
  preambleAndNumberAndValue(x,'A');
}


void Ansiterm::down(int x)
{
  preambleAndNumberAndValue(x,'B');
}


void Ansiterm::forward(int x)
{
  preambleAndNumberAndValue(x,'C');
}


void Ansiterm::backward(int x)
{
  preambleAndNumberAndValue(x,'D');
}


void Ansiterm::eraseLine()
{
  preamble();
  Serial.write('2');
  Serial.write('K');
}


void Ansiterm::eraseScreen()
{
  preamble();
  Serial.write('1');
  Serial.write('J');
}


void Ansiterm::setBackgroundColor(int color)
{
  setAttribute(color + 40);
}


void Ansiterm::setForegroundColor(int color)
{
  setAttribute(color + 30);
}


void Ansiterm::boldOn()
{
  setAttribute(BOLD_ON);
}


void Ansiterm::boldOff()
{
  setAttribute(BOLD_OFF);
}


void Ansiterm::italicsOn()
{
  setAttribute(ITALICS_ON);
}


void Ansiterm::italicsOff()
{
  setAttribute(ITALICS_OFF);
}


void Ansiterm::underlineOn()
{
  setAttribute(UNDERLINE_ON);
}


void Ansiterm::underlineOff()
{
  setAttribute(UNDERLINE_OFF);
}


void Ansiterm::strikethroughOn()
{
  setAttribute(STRIKETHROUGH_ON);
}


void Ansiterm::strikethroughOff()
{
  setAttribute(STRIKETHROUGH_OFF);
}


void Ansiterm::inverseOn()
{
  setAttribute(INVERSE_ON);
}


void Ansiterm::inverseOff()
{
  setAttribute(INVERSE_OFF);
}


void Ansiterm::reset()
{
  setAttribute(RESET);
}


void Ansiterm::defaultBackground()
{
  setAttribute(DEFAULT_BACKGROUND);
}


void Ansiterm::defaultForeground()
{
  setAttribute(DEFAULT_FOREGROUND);
}


void Ansiterm::fill(int x1, int y1, int x2, int y2)
{
  for (int x = x1; x <= x2; x++)
  {
    for (int y = y1; y <= y2; y++)
    {
      xy(x,y);
      Serial.print(' ');
    }
  }
}


/* private functions */
void Ansiterm::preamble()
{
  Serial.write(ESCAPE);
  Serial.write(BRACE);
}


void Ansiterm::preambleAndNumberAndValue(int x, char v)
{
  preamble();
  Serial.print(x,DEC);
  Serial.write(v);
}


void Ansiterm::setAttribute(int a)
{
  preambleAndNumberAndValue(a, 'm');
}

A test program that puts it through its paces is:
Code:
#include <Ansiterm.h>

char * messages[][3] = {{"Name", "Age", "Favorite Sport"}, {"Bruce", "42", "Arduino"}, {"John", "23", "Baseball"}, {"Joel", "9", "Swimming"}, {"Phoebe", "14", "Highland Dancing"}};

Ansiterm ansi;
void setup() {
  Serial.begin(38400);
}

void loop() {
  splash("Testing 'forward', 'backward', 'up', 'down', and overwriting ...");
  ansi.home();//works
  ansi.eraseScreen();
  ansi.setBackgroundColor(BLUE);//works
  ansi.setForegroundColor(GREEN);//realterm doesn't do this, macos does
  ansi.forward(10);//works
  Serial.write("10");
  ansi.forward(10);
  Serial.write("20");
  ansi.forward(10);
  Serial.write("30");
 ansi.down(1);

  ansi.setBackgroundColor(RED);
  ansi.setForegroundColor(WHITE);
  Serial.print("White on red, to be erased");
  delay(1000);
  ansi.eraseLine();//works
  ansi.up(1);//works
  ansi.backward(50);
  Serial.print("One line above, this to be written over");
  ansi.backward(20);
  ansi.setForegroundColor(BLACK);
  delay(2000);
  Serial.print("this appears over the last line");
  delay(2000);
  splash("Testing tabs (doesn't seem to work)");
  ansi.setTabAtColumn(33);//doesn't seem to work
  ansi.setTabAtColumn(66);
  Serial.write(9);
  Serial.write("33");
  Serial.write(9);
  Serial.write("66");
  
  splash("Testing xy function ...");
  ansi.setBackgroundColor(YELLOW);
  ansi.setForegroundColor(BLACK);
  ansi.eraseScreen();
  
  for (int x = 1; x < 60; x+=10) {
    delay(200);
    for (int y = 1; y < 14;  y +=2) {
      ansi.xy(x,y);
      Serial.print(x,DEC);
      Serial.print(",");
      Serial.print(y,DEC);
      delay(200);
    }
  }
  
  ansi.eraseScreen();
  delay(1000);
  splash("Making a table ...");
  //ansi.setBackgroundColor(MAGENTA);
  //ansi.setForegroundColor(YELLOW);
  for (int x = 0; x < 3; x++) {
    for (int y = 0; y < 4; y++) {
      ansi.xy(x*20,y+1);    
    if (y == 0) {
      ansi.setForegroundColor(GREEN);
    }
    else {ansi.setForegroundColor(WHITE);
    }
    Serial.print(messages[y][x]);
    }
  }
  delay(4000);
  ansi.eraseScreen();
}

void splash(char * message) {
    ansi.setBackgroundColor(BLACK);
   ansi.eraseScreen();//works
  ansi.home();
  ansi.setBackgroundColor(GREEN);
  Serial.print(message);
  delay(1000);
      ansi.setBackgroundColor(BLACK);
   ansi.eraseScreen();
}

4  Forum 2005-2010 (read only) / Development / Re: A Satellite Tracking Library for the Arduino on: November 04, 2009, 05:07:57 pm
There is a further application of this library demonstrated in the following youtube video:
5  Forum 2005-2010 (read only) / Development / Re: A Satellite Tracking Library for the Arduino on: October 25, 2009, 07:24:26 am
The project website, with intro video, is at http://sites.google.com/site/qrptracker/home
6  Forum 2005-2010 (read only) / Development / A Satellite Tracking Library for the Arduino on: October 25, 2009, 01:24:05 am
I've released my Arduino satellite tracking  project, entitled qrpTracker.

 qrpTracker includes a library that is a port of the long-standing Plan13 satellite tracking algorithm, and another library that stores and retrieves Keplerian elements. (These are the basic who, what where of satellite tracking.) There is also a separate library to control a FT-817 amateur radio through a hardware serial port.

On its own, the Arduino with an ATMega328 at 16 MHz can store data for about 13 satellites in EEPROM and can process one satellite's location every 10ms. There's lots of programming space left over after the Plan13 and EEPROM code.

Unfortunately, this BB software will not let me post links, so I can't direct you to the project website, introductory video or even to the googlecode repository. It says I can post links after one posting without links, so if anyone's interested, I'll do that as a follow-up.
7  Forum 2005-2010 (read only) / Interfacing / video: stand-alone satellite tuning with Arduino on: December 01, 2009, 01:08:14 pm
The following one-minute video shows a breadboarded arduino tracking two different satellites and controlling a radio attached by a serial port, so as to compensate for the doppler shift of the satellite's transmissions:



The code to control the radio, track the satellites, to store and retrieve the satellite elements and to signal the satellite's position in morse code are provided as Arduino libraries here:

http://code.google.com/p/qrptracker/
8  Forum 2005-2010 (read only) / Interfacing / Success with DS32C35 RTC and FRAM on: November 17, 2009, 07:30:52 am
[Copied from my blog: http://ve9qrp.blogspot.com]

I've been breadboard-testing the DS32C35 RTC after soldering this SOIC-20 onto a sparkfun breakout board, and I'm happy with what I've got: for Arduino use, everything 'just works'.

The beauty of this chip and its siblings in the Maxim line is that it comprises its clock crystal and it has some intelligence on board that keeps the clock highly accurate. This particular version includes 8 kB of FRAM, which unlike EEPROM can be read written an unlimited number of times. Both the RTC and the FRAM are accessible through the I2C line.

First the RTC. Not being interested in anything but the date and time, I was able to use the DS1307 library at http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1191209057 to access this RTC, since its I2C address is the same one used by other Maxim chips like the DS1307. You don't need to seed the RTC for it to start going, so it's easy to see if the oscillator is working or not.

Here's some code I use to test that library:
Code:
#include <Wire.h>

#include <DS1307.h>
#define TIMEOUT 30 * 1000

void setup() {
  Serial.begin(57600);
}

void loop() {
  if (Serial.available() > 0) {
    char value = Serial.read();
    if (value == 'T') {setTime();}
    if (value == 'R') {sayTime();}
    if (value == 'A') {Serial.println("Hi there");}
  }
}

boolean setTime() {
   //9:55:12 am on Christmas Day, 2009 //09122509065512
 Serial.println("TZ");
 long startTime = millis();
 while (Serial.available() < 14) {
    if (millis() - startTime > TIMEOUT) {
      Serial.println("F");
      return false;
    }
}
  char  twoDigits[2];
  readTwo(DS1307_YR,twoDigits);
   readTwo(DS1307_MTH,twoDigits);
   readTwo(DS1307_DATE,twoDigits);
   readTwo(DS1307_DOW,twoDigits);
   readTwo(DS1307_HR,twoDigits);
   readTwo(DS1307_MIN,twoDigits);
   readTwo(DS1307_SEC, twoDigits);
      Serial.println("T");
      return true;
  

}
  
  void readTwo(int value, char * twoDigits) {
  
    twoDigits[0] = Serial.read();
    twoDigits[1] = Serial.read();
    twoDigits[2] = '\0';
    Serial.println(twoDigits);
    
    RTC.set(value, atoi(twoDigits));
 
}
  
  void sayTime() {
    Serial.print(RTC.get(DS1307_YR,true));
    Serial.print(" ");
    Serial.print(RTC.get(DS1307_MTH,false));
    Serial.print(" ");
    Serial.print(RTC.get(DS1307_DATE,true));
    Serial.print(" ");
    Serial.print(RTC.get(DS1307_HR,true));
    Serial.print(":");
    Serial.print(RTC.get(DS1307_MIN,true));
        Serial.print(":");
        Serial.println(RTC.get(DS1307_SEC,true));
  }

Second, the FRAM. This, too, I was able to access through pre-existing code http://www.arduino.cc/playground/Code/I2CEEPROM which I'd used for a 24LC512 chip.

The DS3232 is a clock-only version of this chip in a SOIC-16 format.
9  Forum 2005-2010 (read only) / Exhibition / Re: Amateur satellite tracking and tuning on: February 13, 2010, 03:18:38 pm
KenH --

The code is all available in svn at http://code.google.com/p/qrptracker/ or comprises standard libraries for things like Realtime clocks.

The most important parts are, first, the satellite tracking library, which is a port of James Miller's Plan13. http://code.google.com/p/qrptracker/source/browse/#svn/trunk/Arduino/libraries/Plan13

The library entitled TleStoreCallback facilitates the storage and retrieval of satellite three line elements in EEPROM, I2C ROM or what have you. (The callback approach means that the way in which the bytes are stored and retrieved can be determined at the time of the construction of the object.)

Finally, there's the FT817 library, which controls the FT817 radio. I hope to port this also to the Kenwood  THD-7a handheld radio, so I will probably make a superclass for all radios.

The Sketches/satpack.pde file puts all this together in a loop that polls the 10 tles stored in the EEPROM for a visible satellite, tunes the radio appropriately and response to a button push by changing satellite modes and from satellite to satellite if more than one is up.
10  Forum 2005-2010 (read only) / Exhibition / Re: Amateur satellite tracking and tuning on: February 12, 2010, 11:18:35 pm
designer2k2 --

The Arduino is doing something that until now has required a full computer.

This task has two components. To use a communication satellite, first you need to know when it is visible to your station and in what direction. This 'tracking'  requires a computer/microcontroller to compute the position of the satellite, each second or so and then compare this to where you are on earth.

Once you know the satellite is visible, you have another problem, and that is that the frequencies on which it is receiving and transmitting do not stay still; they shift like the whistle of a train passing by. Because the frequency of the satellite's radio link is much higher than the train whistle, and the satellite much faster, this 'doppler' shift is in the 10's of kHz for some satellites.

So in this video the Arduino is tracking the satellite and changing the receiving and transmitting frequencies of the radio so that it can talk to a satellite. In the second half of the video, it is tuning in a single tone morse code signal, which, despite the doppler shift, is staying within a 100Hz range, a very good result for any tracking program, much less one that runs on $4 silicon.

The hardware side of this is going to sit on a 1" x 2.5" board that snaps onto an Arduino Mini Pro. With the 328's EEPROM, the qrpTracker can keep track of about 10 satellites, tuning the radio as each appears.

11  Forum 2005-2010 (read only) / Exhibition / Amateur satellite tracking and tuning on: February 12, 2010, 03:08:01 pm
The following video shows a breadboarded Arduino automatically tuning a amateur radio's transmitting and receiving frequencies so as to allow two-way communications through a satellite. It also shows the accuracy of the doppler tuning while tracking a single satellite's tone through its pass:

http://www.youtube.com/user/VE9QRP#p/a/u/0/TP_fq_frqKw

The project is blogged at http://ve9qrp.blogspot.com
12  Forum 2005-2010 (read only) / Exhibition / Satellite Tracker and Tuner on: February 05, 2010, 09:54:00 am
The following video shows the current state of my
satellite-tracker-on-an-arduino project. It shows the project's first two-way contacts via an amateur satellite and  its stability while tracking the signal of a satellite in low earth orbit as it changes frequency due to doppler shift.

http://www.youtube.com/user/VE9QRP#p/a/u/0/TP_fq_frqKw
Pages: [1]