Shop OBEX P1 Docs P2 Docs Learn Events
Print directly from the BS2 — Parallax Forums

Print directly from the BS2

Luis_PLuis_P Posts: 246
edited 2012-05-08 10:11 in BASIC Stamp
I will love to be able to use the Sparkfun COM-10438 thermal printer with the BS2 Stamp!
http://www.sparkfun.com/products/10438
It has been used with arduino but I don't know how to use C+ or whatever is that language. CAN ANYBODY OUT THERE TRANSLATE TO BASIC? I will reward! :)

Code:
' Sparkfun Thermal Printer Test (COM-10438)

#include
NewSoftSerial Thermal(2, 3); // printer RX to digital 2, printer TX to digital 3

int heatTime = 80;
int heatInterval = 255;
char printDensity = 15;
char printBreakTime = 15;

void setup()
{
Serial.begin(57600); // used for debugging via serial monitor
Thermal.begin(19200); // used for writing to the printer
initPrinter();
}

void initPrinter()
{
//Modify the print speed and heat
Thermal.print(27, BYTE);
Thermal.print(55, BYTE);
Thermal.print(7, BYTE); //Default 64 dots = 8*('7'+1)
Thermal.print(heatTime, BYTE); //Default 80 or 800us
Thermal.print(heatInterval, BYTE); //Default 2 or 20us
//Modify the print density and timeout
Thermal.print(18, BYTE);
Thermal.print(35, BYTE);
int printSetting = (printDensity<<4) | printBreakTime;
Thermal.print(printSetting, BYTE); //Combination of printDensity and printBreakTime
Serial.println();
Serial.println("Printer ready");
}

void loop()
{
Thermal.println("HELLOW WORLD!");
Thermal.print(10, BYTE); // Sends the LF to the printer, advances the paper
Thermal.print(" Millis = ");
Thermal.println(millis());
Thermal.print(10, BYTE);
Thermal.print(10, BYTE);
do { } while (1>0);
}

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-09-09 09:17
    I think you just need to set your serout to the correct baud (the program you posted uses 19200 bps to communicate with the printer. The printer just uses a normal serial line.

    Duane
  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-09 09:28
    These are the definitions you've given above:

    printerPin PIN 3
    heatTime CON 80
    heatInterval CON 255
    printDensity CON 15
    printBreakTime CON 15

    To initialize the printer:

    SEROUT printerPin, 32, [27, 55, 7, heatTime, heatInterval, 18, 35, (printDensity<<4) | printBreakTime ]

    An example of an output:

    SEROUT printerPin, 32, ["HELLO WORLD!", 10 ]

    Note that the BS2 is not intended to work at 19200 Baud which is the normal Baud for this printer. It probably will work, but don't be surprised if there are occasional timing problems at this Baud. It's not at all clear how to change the printer to slower Bauds. The documentation from SparkFun doesn't mention it.

    Be sure to look at the "What's a Microcontroller?" tutorial and the "Basic Stamp Syntax and Reference Manual", both downloadable from Parallax's Download webpage. The Stamp Manual shows how to use the SEROUT statement.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-09-09 10:06
    Luis,

    I've had one of these printers for a couple of months. Today is the first time I powered it up.

    I wrote a small program for the Propeller to use the printer. I added the initialization bytes as Mike shows.

    At first the printer wasn't printing well but I noticed I had the low current setting on my power supply. These little printers can suck a lot of juice. I wouldn't power it from your BS board directly (I don't know how much current it can supply). At 6.3V the max current was 1.054A when the printer was printing.

    These a fun little printers. I'm glad you asked about it.

    I couldn't find how to change the baud either.

    Duane

    Edit: The current at 5V was 0.994A. The current at 9V was 1.220A. The print quality was worse at 5V compared with 6.3V. The print quality a 6.3V and 9V looked the same to me. I used the settings in the program Luis posted.
  • PublisonPublison Posts: 12,366
    edited 2011-09-09 10:14
    Could you use a BS2px? It should be able to do 19200 baud. It's still on sale:

    http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/CategoryID/9/List/0/SortField/0/Level/a/ProductID/392/Default.aspx

    But a Propeller still would be cheaper.
  • Luis_PLuis_P Posts: 246
    edited 2011-09-09 10:39
    Thanks. Could you please share your Propeller code?
    You said you couldn't find how to change the baud but works anyways?

    QUOTE=Duane Degn;1034455]Luis,

    I've had one of these printers for a couple of months. Today is the first time I powered it up.

    I wrote a small program for the Propeller to use the printer. I added the initialization bytes as Mike shows.

    At first the printer wasn't printing well but I noticed I had the low current setting on my power supply. These little printers can suck a lot of juice. I wouldn't power it from your BS board directly (I don't know how much current it can supply). At 6.3V the max current was 1.054A when the printer was printing.

    These a fun little printers. I'm glad you asked about it.

    I couldn't find how to change the baud either.

    Duane

    Edit: The current at 5V was 0.994A. The current at 9V was 1.220A. The print quality was worse at 5V compared with 6.3V. The print quality a 6.3V and 9V looked the same to me. I used the settings in the program Luis posted.[/QUOTE]
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-09-09 11:14
    Luis,

    Here's the Propeller code I wrote.
    CON
      _CLKMODE = XTAL1 + PLL16X
      _CLKFREQ = 80_000_000
      _PrinterBaud = 19200
      _DebugBaud = 57600
      _PrinterTx = 0
      _PrinterRx = 1
     
     
    OBJ
      Debug : "fullduplexserial"
      Print : "fullduplexserial"
    PUB Main | localCharacter
      Debug.start(31, 30, 0, _DebugBaud)
      waitcnt(clkfreq / 1000 + cnt) ' wait for serial driver cog to start
      Print.start(_PrinterRx, _PrinterTx, 0, _PrinterBaud)
      waitcnt(clkfreq * 3 + cnt) ' wait for serial driver cog to start
     
      Print.tx(27)
      Print.tx(55)
      Print.tx(7)
      Print.tx(80)
      Print.tx(255)
      Print.tx(18)
      Print.tx(35)
      Print.tx((15<<4)|15)
      Print.str(string("Printer Ready", 13, 10))
      Print.str(string("Hello World", 13, 10))
     
      repeat
        localCharacter := Debug.rxcheck
        if localCharacter <> -1 and localCharacter <> 0
          Print.tx(localCharacter)
     
        localCharacter := Print.rxcheck
        if localCharacter <> -1 and localCharacter <> 0
          Debug.tx(localCharacter)
     
     
    

    After its "Hello World", it takes whatever is entered through the terminal window and sends it to the printer. Any information sent from the printer is displayed in the terminal window.

    I haven't seen any information coming from the printer yet.

    I found it interesting that the printer uses a 3.3V TTL interface. I thought it would be 5V.

    Duane
  • xanatosxanatos Posts: 1,120
    edited 2011-09-25 17:24
    Just a quick thanks! To you all for this post, especially Mike, for the code snippets that answered all my questions in one second! :-)

    Dave
  • not4guynot4guy Posts: 1
    edited 2012-05-08 06:46
    Thank you Mike!!!
    I have been trying to make this printer work for weeks, it's been hit and miss.....
    it will work for me if I use a 9V battery, but not if pluged in to the wall. is that crazy?
  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-08 10:11
    If it'll work with a 9V battery, but not with an AC supply, there must be something wrong about the AC supply, yes? Perhaps the AC supply can't supply enough current? Even though a 9V battery is pretty puny in terms of total capacity, an alkaline 9V can usually produce pretty good peak currents for very short periods of time while an AC supply may not be able to do that. The datasheet for an Eveready alkaline 9V shows that it can supply 300mA for an hour before dying (voltage dropping below 6V).
Sign In or Register to comment.