Author Topic: Need Help with Arduino Uno Sketch to Create ASCII Characters  (Read 16510 times)

0 Members and 1 Guest are viewing this topic.

Offline Hideki

  • Frequent Contributor
  • **
  • Posts: 256
  • Country: no
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #25 on: April 13, 2014, 08:14:03 pm »
You can get analog signals from the arduino too. Build a simple R2R DAC from resistors and connect it to the arduino pins. Maybe start out with two bits to get four different analog levels? All you need is four resistors.

When you figure out how that works you can add more bits using more resistors. 8 bits gets you 256 different levels, which should be more than enough for testing.
See for example http://forum.arduino.cc/index.php?topic=150147.0

As you see you need two resistors for each additional bit. One resistor being twice the value of the other. The exact values are not too critical. You can use all the same value if you like, since two in series makes double the value, or two in parallel makes half.

Note: This step may be too difficult so soon, but to change all bits at once, write directly to the port, bypassing the slow digitalWrite function.

Or... use the analogOut and put a lowpass filter on the pin, but this limits you to rather slow bitrates.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #26 on: April 17, 2014, 02:16:11 pm »
@Hideki -  I doubt you can get the DAC performance required to manipulate the individual bits in (even a slow) serial data stream...
I was initially thinking the same, but suggested the external DAC to provide real-time 'distortion' of the serial data levels as expected in the original posts.
The bit-interrupt feedback also provides a tidy way of knowing when to burp & fart in order to manipulate individual bits as they pass through the gain amp.
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #27 on: April 20, 2014, 01:37:36 am »
Ok, here is another attempt at being able to generate strings of various ASCII characters.....

These HP/Agilent Pulse Generators looks like they might be able to create ASCII byte patterns by providing relatively easy control over timing, amplitude, etc.  At $800 - 1700 it makes no sense for my purposes but maybe someone knows of a (considerably) less expensive device that might suffice?

http://www.ebay.com/itm/HP-Agilent-8110A-Pulse-Generator-81106A-150MHz-with-81103A-Output-Card-/141081716744?pt=LH_DefaultDomain_0&hash=item20d9202808

http://www.ebay.com/itm/HP-Agilent-81101A-Pulse-Generator-50-MHz-Clean-Working-with-Warranty-/261455034092?pt=LH_DefaultDomain_0&hash=item3cdfef36ec

http://www.ebay.com/itm/AGILENT-81101A-PULSE-GENERATOR-/271005892346?pt=LH_DefaultDomain_0&hash=item3f1935befa

Not even clear the above models will offer enough flexibility to generate strings for ASCII characters:
http://cp.literature.agilent.com/litweb/pdf/5980-1215E.pdf


Older model?:

http://www.ebay.com/itm/Agilent-HP-8118A-50-MHz-Dual-Channel-Pulse-Generator-/220479463459?pt=LH_DefaultDomain_0&hash=item335599a023

I'm guessing the models below will not allow the variations needed to create ASCII bytes (other than maybe highly symmetrical character patterns such as a capital U), right?

http://www.ebay.com/itm/Hewlett-Packard-HP-Agilent-8013B-Pulse-Generator-/360405990545?pt=LH_DefaultDomain_0&hash=item53e9defc91

http://www.ebay.com/itm/HP-Agilent-8003A-Pulse-Generator-L180-/131155740155?pt=LH_DefaultDomain_0&hash=item1e897dc5fb

And finally, it looks like for $83k  :-DD this should be doable:
http://www.home.agilent.com/en/pd-1000004569%3Aepsg%3Apro-pn-81134A/pulse-pattern-generator-335-ghz-dual-channel?&cc=US&lc=eng

I definitely don't need 3 GHz; maybe 1 MHz would be nice.

Thanks for any ideas.  EF


« Last Edit: April 20, 2014, 02:07:15 am by Electro Fan »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #28 on: April 20, 2014, 02:05:11 am »
If you understand what you are trying to do, it shouldn't take more than $10 and maybe 15 minutes of programming to do it.
================================
https://dannyelectronics.wordpress.com/
 

Offline Hideki

  • Frequent Contributor
  • **
  • Posts: 256
  • Country: no
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #29 on: April 20, 2014, 02:10:31 am »
You DO understand that the Arduino has hardware serial on Digital Pin 1, right? You change the timing with Serial.begin(9600) or some other speed, and send data with Serial.write(byte).

If you want to change the amplitude of all the high pulses, then a simple potentiometer will do that. It costs much less than $800. A voltage divider with two resistors will do in a pinch.
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #30 on: April 20, 2014, 04:12:52 am »
Ok, maybe I'm just a little confused (or maybe a lot confused)?

At the start of the thread entitled "Need Help with Arduino Sketch to Create ASCII Characters" I posted an explanation of what I was trying to accomplish and what I had wired together (with just Pin 13 and GND) and programmed with the Uno.

That resulted in various posts including some saying that perhaps it was going to be more difficult than anticipated (for example, Reply #23, concluded "It ain't going to be a walk in the park - but I think it's possible - and quite interesting to consider !"  Hideki made some follow-on suggestions and SL4P raised some more questions in Reply #26).

Now we have dannyf saying "if you understand what your are trying to do, it shouldn't take more than $10 and maybe 15 minutes of programming to do it."  Not to make too fine of a distinction, but I think I understand what I'm trying to do, just not how to do it.

Anyone want to suggest what specifically would be the Uno wiring diagram and the specific code that would enable HI and LOW pulses to be generated so as to create ASCII character strings?

Thanks, EF
« Last Edit: April 20, 2014, 04:19:24 am by Electro Fan »
 

Offline Dago

  • Frequent Contributor
  • **
  • Posts: 659
  • Country: fi
    • Electronics blog about whatever I happen to build!
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #31 on: April 20, 2014, 11:00:25 am »
Anyone want to suggest what specifically would be the Uno wiring diagram and the specific code that would enable HI and LOW pulses to be generated so as to create ASCII character strings?

Code: [Select]
Serial.begin(9600);
Serial.println("ASCII string");

That's all you need if you just use the USART... Connect whatever you want to pins 0 (RX) and 1 (TX).
Come and check my projects at http://www.dgkelectronics.com ! I also tweet as https://twitter.com/DGKelectronics
 

Offline Hideki

  • Frequent Contributor
  • **
  • Posts: 256
  • Country: no
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #32 on: April 20, 2014, 11:08:31 am »
Code: [Select]
void setup() {
  Serial.begin(9600);  // 9600 bits per second
}

void loop() {
  Serial.write(65); // send this byte
}

Switch to pin 1 as the output instead of pin 13 and this should send 65 continously (ASCII for the letter 'A').

Once you get that going you can start changing the output level to something less than 5 volts (I don't know WHY, but you seem to think this is important).
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #33 on: April 20, 2014, 12:31:58 pm »
Perhaps I misread OP, but in the chain of discussion, thee was a requirement to vary bit timing and bit levels (i.e. simulate line faults).

If this is not the case then yes 15, and 10 minutes will close the thread. 

But my lesson learned - in a forum, perhaps the question is not what it seems.
Cheers, and let us know how you go.
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #34 on: April 20, 2014, 08:56:08 pm »
Hideki, Dago, SL4P – Thanks

Hideki, I’ve set pin 1 (rather than 13) for output.  Pin 0 (not GND) should be used for the other wire, right?  (Same as suggested by Dago, right?)

Thanks, EF
 

Offline Hideki

  • Frequent Contributor
  • **
  • Posts: 256
  • Country: no
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #35 on: April 20, 2014, 09:09:53 pm »
Yes, use pin 1, but you shouldn't add extra code to set it to an output. That happens automatically when calling Serial.begin.

Pin 0 is RX (Receive) for sending data _into_ the Arduino from some other device. At the level you're at, you really shouldn't be trying that today.

The only "other wire" you need, is GND. Connect that the the oscilloscope probe's ground clip.
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #36 on: April 20, 2014, 09:27:26 pm »
Hideki, Thanks.

Ok, for now I have just pin 1 and GND connected to the scope.  Your sketch using Serial.write(65) uploads fine that way.

The scope reads 5.01 volts.

The scope decoder is set for 9600 and RS232.

The scope is set on 8 data bits plus 1 stop bit.  Parity is none.  Packet is off.  Packet End is Null.  Polarity is Normal.  Endian is LSB.

At 200us I can see two full bytes on the scope display at one time. 

With the above settings the Binary readout is 11110101 which isn't "A".

Any suggestions on some possible adjustments?  Thanks again, EF
« Last Edit: April 20, 2014, 09:30:28 pm by Electro Fan »
 

Offline Hideki

  • Frequent Contributor
  • **
  • Posts: 256
  • Country: no
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #37 on: April 20, 2014, 09:47:51 pm »
You're not using RS232 levels (+3 to +15 volts and -3 to -15 volts). This is normal serial UART levels of 0 and 5 volts.

From the manual it looks like you can change Polarity from Negative to Positive to get around this issue.
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #38 on: April 20, 2014, 10:07:05 pm »
Hideki,

Could be some progress here.  :)

On the trigger Rigol gives the following options:

Edge, Pulse, Runt, Slope, Video, Pattern, Setup/Hold, RS232, I2C, and SPI

I think RS232 does inform the scope to look for the +3/+15 and -3/-15 volts, but my sense is that the trigger is not that sensitive and it can determine a HI from a LOW pretty easily.  (So maybe I can leave it on RS232 and just adjust the polarity?)

On the decoder the Rigol gives the following options:
Parallel, RS232, I2C, and SPI.

I'm still playing with it but any suggestions on the combination of trigger and decoder options are welcome.

Thanks!  EF

PS, before we go too far down any wrong paths (and one of the reasons I thought we were getting close with the analog pins) I just wanted to restate that the eventual goal is to be able to at a minimum generate bits that make strings of bytes (render words on the display, etc.) - not because I like seeing words on the display but to gain control and understand the patterns including the control characters. Ideally I'd like to be able to adjust single bits so as to adjust bytes from within into new bytes (rather than just assign values like 65).  What I'd really like to be able to do is to adjust HIs and LOWs to toggle start and stop bits as well as data bits - but maybe we can save some of this for "Phase 2" :)  Thanks again
« Last Edit: April 20, 2014, 10:29:32 pm by Electro Fan »
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #39 on: April 20, 2014, 10:12:57 pm »
Is there any real world applications for what you're fiddling about with here?  I understand about learning as an exercise, but I can't really work out what you're trying to learn.   :-//
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #40 on: April 20, 2014, 10:23:46 pm »
Is there any real world applications for what you're fiddling about with here?  I understand about learning as an exercise, but I can't really work out what you're trying to learn.   :-//

As mentioned in the "PS" I added above I want to be able to see exactly where each bit, including control bits such as start and stop bits end and begin and be able to control the full sequence of bits.  When I can adjust bits one at a time including start and stop bits, parity bits, etc. and get the data bytes and special characters (spaces, punctuation, etc.) to reliably render without errors I will feel like I have figured it out.  This will not earn a course credit much less help earn a degree in anything.  It is strictly curiosity and a hobby.

Net, net:  I just want to be able to set, control, and generate bits and have them display predictably as waveforms and decode reliably as bytes according to the ASCII character table.
« Last Edit: April 20, 2014, 10:35:41 pm by Electro Fan »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #41 on: April 20, 2014, 11:06:32 pm »
Quote
That's all you need if you just use the USART.

That didn't take 15 minutes to write, right? :)

Quote
I want to be able to see exactly where each bit, including control bits such as start and stop bits end and begin and be able to control the full sequence of bits.

Dago's code would allow you to do precisely that.

What you are trying to do is really simple, as many have pointed out to you - it cannot be simpler than this! Quite frankly, you seem to be speaking a different language here. If you find this frustrating, I would suggest that you go back and take an intro level class in electronics.

Having said that, here is what I would suggest to you:

1) take Dago's code and modify it slightly to make it easier for you:

Code: [Select]
  Serial.println("A");
  delay(500);

Every 500ms, it will send "A" (plus return and potentially null), so you can watch it on your scope.

2) Take a picture of that waveform, and go check on uart protocol and make comparison.

3) Once you have really understood that, go get the datasheet for your mcu and read about the usart module and compare it to how arduino did it.

4) make changes to it as you need.

Again, this thing is really simple and don't work too hard to make it complicated.
================================
https://dannyelectronics.wordpress.com/
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #42 on: April 21, 2014, 01:04:47 am »
dannyf (and everyone), Thanks for the continued "encouragement"  :)

Attached is a file produced with the suggested code.

A few questions (some of which are probably separate from the original "goal"):

1. What is causing the Line Feeds to be displayed?  Something embedded in the Uno?

2. What causes the occasional error characters such as the "*" and the "5"?

3. The counter remains pretty stable around 3.16KHz but the frequency measurement (which shows 3.125kHz in the image) bounces around between about 2.5kHz and >5kHz.  Is the frequency measurement not able to update the display as reliably/quickly as the counter?

4. I'm guessing that the narrow lines at the top and bottom of the square waves are something that might be cleaned up with a better ground connection?  (They clean up if I insert a 50 Ohm terminator between the test leads and the scope - as shown in the bottom photo.)

Thanks, EF
« Last Edit: April 21, 2014, 01:11:54 am by Electro Fan »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #43 on: April 21, 2014, 01:23:26 am »
Let me just repeat what I said earlier: you should take an intro level class at any decent colleges. It will get you where you want to go a lot faster.

Quote
Is the frequency measurement not able to update the display as reliably/quickly as the counter?

That measurement depends on the baud rate and the content being transmitted.

================================
https://dannyelectronics.wordpress.com/
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #44 on: April 21, 2014, 01:25:47 am »
Having fun now (getting predictable results).  Thx for all the help!
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #45 on: April 21, 2014, 01:28:51 am »
Let me just repeat what I said earlier: you should take an intro level class at any decent colleges. It will get you where you want to go a lot faster.

Quote
Is the frequency measurement not able to update the display as reliably/quickly as the counter?

That measurement depends on the baud rate and the content being transmitted.

Yep, I get it about the class - if I just didn't have a day job :)
In the meantime (I know what you guys are thinking  |O) this the classroom  :)

I get the notion of the baud rate.... why does the frequency measurement not give the same result as the counter?  Thanks
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #46 on: April 21, 2014, 01:35:58 am »
Quote
1. What is causing the Line Feeds to be displayed?  Something embedded in the Uno?
Quote

Code: [Select]
Serial.println("A");

Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). This command takes the same forms as Serial.print().

Code: [Select]
Serial.print("A");

Print just sends a single ascii character = A
« Last Edit: April 21, 2014, 01:38:09 am by retrolefty »
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #47 on: April 21, 2014, 02:06:21 am »
Quote
1. What is causing the Line Feeds to be displayed?  Something embedded in the Uno?
Quote

Code: [Select]
Serial.println("A");

Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). This command takes the same forms as Serial.print().

Code: [Select]
Serial.print("A");

Print just sends a single ascii character = A

retrolefty - Thanks!  That is very helpful!

Electro Fan
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #48 on: April 21, 2014, 04:09:33 am »
Quote
Code: [Select]
  Serial.println("A");
  delay(500);

Keep mind that this code will output 'A' as well as the line terminator(s).
Don't ask a question if you aren't willing to listen to the answer.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Need Help with Arduino Uno Sketch to Create ASCII Characters
« Reply #49 on: April 21, 2014, 04:14:09 am »
What happened to...
...have the ability to generate test signals that are effectively ASCII characters while having control over the amplitude and pulse durations and maybe the underlying clock frequency on which the pulses ride.
Don't ask a question if you aren't willing to listen to the answer.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf