element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Serial Config help.
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 31 replies
  • Subscribers 420 subscribers
  • Views 4972 views
  • Users 0 members are here
Related

Serial Config help.

YT2095
YT2095 over 14 years ago

I need to configure the Serial on an Arduino to match a very strange Printer, I`m not even sure it`s possible with an Arduino?

it needs to be:

 

1200 Baud

1 Start bit

7 Data bits (LSB first)

1 Parity Bit (Even)

and 2 Stop Bits.

 

Does anyone know how config for this in Arduino, or even if it`s possible?

 

Thanks image

  • Sign in to reply
  • Cancel

Top Replies

  • R_Phoenix
    R_Phoenix over 14 years ago in reply to billabott +1
    SoftwareSerial is no different than useing the built in Serial port. I don't know of anything that even still uses the start bit. As far as I know, the serial port on an Arduino is only 3 wires, RX, TX…
  • YT2095
    0 YT2095 over 14 years ago in reply to billabott

    OK, I`ll do that too image

    it`ll likely not be until the weekend though, and in the meantime I`m going to throw this problem OPEN and include PIC chip solutions too.

    I use 16F877a and 18F4550, I think these could also be capable of such a task, perhaps?

     

    meanwhile, i`m going to get some welding done on MINDI, I need a break from all this software stuff!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 14 years ago in reply to YT2095

    I would not know about the PICs but that brings a thought to mind about putting to use additional ICs like a serial to parallel for trouble shooting or solution implementation.  I seem to recall some chips that have the capability to generate more than 8 bits on their serial output pin.  So something with an I2c interface would be an cool option.  Of course the Arduino Uno can and does have the capability but apparently not under the control of SoftwareSerial unless our trick with using type double pays off. 

     

    Wait a second; what software resources are applied when communicating over the I2C wires? Could the I2C packet be configured so that the Univeral receiver (PXP-40) is fooled into printing the desired characters?

     

    N.B. You may want to put a little wait state in the Loop() to give that antique thermal printer enough time to figure out what to do with the bits it is getting.  It is possible that is its problem even now with the 'Hello World' string.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • YT2095
    0 YT2095 over 14 years ago in reply to billabott

    if I were to use other chips, i`d do it from scratch like I did before with a  1200CPS clock, a Binary counter to feed a 74150 and a 10 count RTS for next byte into the 150, the other code would be set with DIP switches.

    parity would be parsed with an inverter on on the LSB (as anything Higher will be an even number anyway).

     

    as for I2C I know very little to nothing about it yet, beyond a single temp sensor anyway image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 14 years ago

    Wow. A lot of people have no clue how serial data works.

     

    1 start bit is pretty standard.

     

    "...don't know anything that still uses it..."

     

    rubbish. EVERYTHING uses it. An idling serial stream is sending "mark" (logic 1 -- which will be a negative voltage if RS-232RS-232 or positive if TTL). When a byte is ready to be sent, the data line is commanded to "space" (logic 0 -- positive if RS-232RS-232 or 0v if TTL). This is your start bit. When the receiver detects the logic 0 it knows to begin timing and extracting the bits.

     

    Yes, LSB first is "normal." No worries there either.

     

    Edit: Never mind extra bit I was adding to Salvador's bitstring. He has it right.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • SGarciaV
    0 SGarciaV over 14 years ago in reply to e14 Contributor

    Hi CookeMonster,

     

    Yeah, that "previous poster" was me! :-)

     

    I believed that UCSR0C was a byte, why do you have 9 bits? I understand that the bits that specify the word length are 3 bits, but 2 of these are in the UCSR0C and the third (MSB) is in the UCSR0B register.(bit 2). Thanks! Salvador

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 14 years ago in reply to billabott

    >Have you tried casting the variable as a double?

    >Here is my idea:

    >Given an AsciiChar Byte which Serial.read() has provided from the Console:

    >NewChar = AsciiChar|0x80;  // set the first bit high so you have the "Start Bit"

     

    A start bit is a 0, not a 1

     

    >DoubleChar = (NewChar * 4) + 3;  // shift the bit pattern left 2 positions and

    >// set the two low order bits high for the "Stop bits"

     

    You are putting them at the wrong end. It comes out of the UART LSB first.

     

    >If softwareserial cannot handle the double, then break it into two bytes

    >and send them one after the other using myserial.write.

     

    You can't do that. There is a start bit on each byte. And a parity bit. And then a stop bit. Two in this case. (logic 1's).

     

    Reading left to right, if you put a scope on it the bits should come out the wire like this (start "S", 7 data bits "X", even parity "P", 2 stop "SS":

     

    S0123456PSS

    0XXXXXXXP11

     

    If another character is ready to be sent, a new start bit is sent (logic 0). If no character is ready, the line remains at logic 1 until one is.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 14 years ago in reply to SGarciaV

    Yes, it should be 8 bits. I counted 7 in your post. Let me put my reading glasses on and look closer. The "1" on the right needs to be 3 bits "in". Back in a flash...

     

    Edit. Yep. I don't know how I counted that wrong. Your string is correct. Original message edited.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 14 years ago

    Ah, I see another problem.

     

    Salvador's "how to set the 7 bit" thing only will work on the original hardware serial port .

     

    OP is trying to do serial on pins 2 & 3.

     

    If you can not put the printer on a hardware serial port, you probably have to write your own (software) serial library -- I'm not aware of any of the software serial versions that support 7 bits and even parity.

     

    No worries -- it is not that hard -- 90% of what you need is available open source, only the partity and adding a second stop bit are required to be added; reduce the sent bits from 8 to 7, change time delay to what you need for 1200 bps. You don't even need the receive code. That is harder to do reliably anyway. Sending is easy.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • SGarciaV
    0 SGarciaV over 14 years ago in reply to e14 Contributor

    Good catch, so setting UCSR0C only works if using pins 0 and 1? Haven't used those in a while, so correct me if these do not correspond to the original hardware serial port. Nevermind - I've got the Arduino in front of me and just checked it. RX and TX are clearly labeled for pins 0 and 1, respectively. Salvador

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 14 years ago in reply to e14 Contributor

    CM says:  (start "S", 7 data bits "x", even parity "P", 2 stop "SS")

     

    If the data line is held high all the time just to let the device know that it is connected, then okay.  I did not know that was the standard; seems a waste of electrons, IMO.

     

    If the parity bit must be present does that printer even use the parity bit?  or ignore it?

     

    So, we have

    newChar = (double((asciiChar * 8) +7)| oxf000);   //  will give  11110xxxxxxxP11

    or

    newChar = (double((asciiChar * 8) +3)| oxf000);   //  will give  11110xxxxxxxP11

    or even

    newChar = ((double((asciiChar * 8) +7) *16) + 15);   //  will give  0xxxxxxxP111111

     

    Is one of those going to work?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
<>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube