Shop OBEX P1 Docs P2 Docs Learn Events
Rx serial byte — Parallax Forums

Rx serial byte

dondedonde Posts: 51
edited 2009-09-14 21:55 in Propeller 1
First of all, I'm a newbie. (It seems like forever!) Here is what I want to do. Rx 5 ASCII numbers from a keypad encoder, send it TX_text onto the screen.

I have done this: Using these Objects: Extended_FDSerial, TV_Text, Numbers, I have built some short code to send a text string to the screen. No external input. But, having trouble how to code for input on pin1 (Rx) from keypad, and to see it on screen. I understand CR (13) has to on the end also. Keypad can't do this. The input will just be 5 numbers, like a ZIP code. I guess it will be an array of 5. Extended_FDSerial is set this way: Serial.start(1,0,0,9600). So, Rx is pin 1 on Prop. The keypad has two outputs. One is the data, and the other is called Valid, which is high with no keypress, and low with keypress. Data is sent after number button is released.

I eventually want to change the number to a hex byte and store it in a known memory location of another program. I'm not asking for coding, but maybe a push in the right direction would be very helpful. Line comments would be great too. Propeller seems pretty hard for me at this point. I've looked at many examples, but syntax just doesn't want to stick. Guess I'm getting old!
Don

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-12 19:51
    Post your code as an attachment to a message. Use the Post Reply button instead of Quick Reply and you'll see a button for the Attachment Manager which can upload your source (.spin) file.

    You really should have some kind of delimiter, either a start character of some sort or a termination character. It doesn't have to be a CR. Without either you can get out of sync so you, the user, doesn't know when a new number begins. You're best off with the existing Extended_FDSerial if you use some kind of termination character. The SetDelimiter method allows you to set an alternative termination character. You might want to use either the rxDec or rxDecTime methods to take the 5 digits and make a number out of them rather than just store them as a string. If you just want the string of digit characters, you could use RxStr or RxStrTime instead. Look at their descriptions in the Extended_FDSerial object.
  • dondedonde Posts: 51
    edited 2009-09-12 22:35
    Hello

    Here is code listing that doesn't work. I see "Start and "End" on screen with a CR symbol just in front of "E" of "End".
    I push a button on the encoder circuit to output a "5". The encoder is connected to pin 1 on the Prop Demo Board.
    Don

    Post Edited (donde) : 9/12/2009 10:40:43 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-12 23:44
    Try this
  • dondedonde Posts: 51
    edited 2009-09-13 01:50
    No, still doesn't work. When I load RAM, I see "Start" and "End", one after the other. very fast. It never quits. I had to do a power shutdown. In fact, even Com Port 3, I use to load programs gave a fatal error. had to do a PC restart, and play with the ports. No problem, got everything back. Tried again, still as above.

    I really don't need "Start" or " End" It was just a way to see something on the screen. What, I want is to just have the Prop code wait for an output from my encoder. It has just 1 button, for now, wired up to a PIC. The number "5" comes out when I push and release the encoder button. I can see a positive going 3.3 volt coded square waves coming out using my scope. It is connected to pin 1 (Rx). I don't need pin0 (Tx) To verify that "5" came out, I want to see the number on the screen. Then, I'll push the button again, and see another "5" , and so on. I'll do this till I get five "5'" 's. Later, I'll wire up the rest of the 10 buttons connected to the PIC, to get any number, up to a string of 5. I then will want to store these numbers, changed to hex, in 5 known memory locations in another program I know about. But, for now the other program is not involved. I just want to see how to do this task.

    I think you understand, but so far, all I get is what happened above. I appreciate your help. Thanks
  • dondedonde Posts: 51
    edited 2009-09-13 02:17
    UPDATE!
    Mike, I commented out the "Start" and "End". Now, I can now see a clear screen. Pushing the encoder button, I DO see characters, but they are all garbage, never a "5", and not every time. Many times, nothing.. So, I must have some kind of timing problem? Got to go now, but work on it tomorrow sometime.
    Thanks...Don
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-13 03:52
    You could leave the "Start" and "End" there. What's happening is that the Propeller is receiving garbage. You might have the Baud wrong (fix - correct it). The encoder might be producing serial characters with the wrong polarity (fix - change the mode to inverted). There might be a lot of electrical noise on the lead from the encoder that the Propeller is confusing with character data (fix - figure out why and quiet it down). Without more information about the encoder, it's impossible to say. Before you can do anything else, you need to get this part working.
  • dondedonde Posts: 51
    edited 2009-09-14 02:40
    Mike,
    I changed the mode to 1, and now I see 5 of the same same character. But they are all the "down arrow" symbol! The down arrow is DEC 5 or $05. It should be DEC 53 or $35. I look at the waveform. It is the code for "down arrow". It looks like this.
    Starting at left: LSB 1, 0, 1, 0, MSB 1, 1, 1, 1
    Inverted: LSB 0, 1, 0, 1, MSB 0, 0, 0 ,0

    I guess the vender programmed the PIC wrong. Or, I'm all wet. I used the Parallax Oscilloscope. I saved it as a .bmp file. I tried to upload it using Attachment Manager below. It uploaded, but couldn't find it. The waveform looks clean and consistent. 5 "down arrows" always are seen on screen. I'm pulling the "pin5" pin on the PIC low through a 330 ohm resistor. It's normally held high with a 10K. Maybe, I can sen you the .bmp as a private e-mail?
    Don
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-14 03:14
    I don't need the .BMP file. You've already identified what's going on. In the FDS file I sent you, just change

    Serial.rx

    to

    Serial.rx + "0"

    Hopefully you can see why it's important to provide much more information than you've done. In this case, information on the keyboard encoder, a datasheet or manual would be ideal if there's a link to an on-line copy.
  • dondedonde Posts: 51
    edited 2009-09-14 04:35
    Mike,
    You are absolutely right. What you said to add, works! I now see 5 fives. Still not sure why the encoder waveform showed the way it did. You have been very helpful. I have learned a lot more in this exercise, and your coding corrections and additions. One thing, I should focus more on what I want to do, before I start. The PIC is from Rentron, under Basic Stamp Projects, "Build a 10-Key Serial Keypad". If you notice, no info about PIC coding. Just send $8!
    Thanks again...Don
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-14 04:50
    If you would explore the links on Rentron's website, you'd see that there's a schematic, code listing, and explanation of the code for this encoder:

    www.rentron.com/PicBasic/Serial-Keys.htm

    That shows you that the serial bytes have the values 1-10 (not 0-9 and not "0".."9") and there's no way to handle an 11th or 12th key (like "*" or "#").
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-14 05:05
    If you've got 10 extra I/O pins, it would be easier to let the Propeller handle the keypad. If you don't have the I/O pins (10) to attach the pushbuttons directly, you could use a 16-pin I2C I/O Expander like the PCF8575 which could be attached to the two I/O pins used for the EEPROM. The PCF8575 even has built-in pullup resistors, so you could just attach the pushbuttons between the I/O pins and ground
  • dondedonde Posts: 51
    edited 2009-09-14 06:02
    What I saw 1st was the schematics and description. I have no experience with PIC Basic or any compilers. So, I just browsed the code. Figured it would interesting to make a 10 button keypad. Right now I just have 1 button wired on a proto board and the PIC. I'll just continue and put it on vector board with the rest of the buttons.

    You may be wondering what the overall plan is. I built up the project in July Circuit Cellar, Internet Weather Display. Appended stuff on screen, which I think looks pretty good. Now, want to add ZIP entry without bringing up program on PC and changing manually. I know the 3 memory locations where the ZIP is located. The only problem, I'm about out of memory. So, really don't have handle on·how to get the encoder app in there. Some say to release code when done with a·section, and bring in new code (like the encoder app). This way beyond me right now. But, now that the button program works, I'll think about it·some more. OK on the 12C expander, but I think my plate is full for a while.

    Anyway, I would have never though of adding "0" to·Serial.rx. Still not sure why.
    Don
  • dondedonde Posts: 51
    edited 2009-09-14 06:26
    i just realized what you said. Looking at the schematic, I don't see a zero key. I don't know how I missed it! I see key 10. Is there a way to send a zero? ZIP's have lots of zeros! Darn, I have not seen this till now! I guess this project was just meant to have 10 keys that could do something, like turn on lights, or start/stop processes, etc.
    Don
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-14 12:48
    What's the difference between a "10" key and a zero key? You just have to test for it like
    x[noparse][[/noparse] i ] := Serial.rx + "0"
    if x[noparse][[/noparse] i ] == "0" + 10
       x[noparse][[/noparse] i ] := "0"
    
  • dondedonde Posts: 51
    edited 2009-09-14 14:15
    I surely have come up with code you just showed me before. I think I'm getting lazy, and you're patiently putting up with it. Everything you've added, changed or suggested does help. A great tutorial.
    Don
  • dondedonde Posts: 51
    edited 2009-09-14 21:55
    Mike,
    The 10 key now puts out zero, nada, "0"! Have a great week.
    Don
Sign In or Register to comment.