Shop OBEX P1 Docs P2 Docs Learn Events
SPI SOLVED - Page 9 — Parallax Forums




  • Values 2 and 4 are RdirPin and DdirPin, which are never changed anywhere in the code. Is that what you intended? If not, you should fix the logic in the code, or tell me what you want it to do and I'll fix it. The Spin code is just a translation of your original C code, and the C code never changes those values either.
  • bbrienbbrien Posts: 561
    edited 2020-08-21 18:34
    I double checked the routine and couldn't find the problem. When you press the north and west buttons the direction should be a logic zero and the south and east buttons should be a logic one.
  • Dave HeinDave Hein Posts: 6,347
    edited 2020-08-21 19:18
    bbrien, your code doesn't make sense. The four variables in question are RmotorPin, RdirPin, DmotorPin and DdirPin. The code never changes RdirPin or DdirPin. It does call low(RdirPin), high(RdirPin), low(DdirPin) and high(DdirPin). That does not change the value of RdirPin or DdirPin. It only changes the voltage on the pins defined by the values of RdirPin and DdirPin. Since these variables are always zero, you are changing the voltage on pin zero.

    If you want to change the values of the variables RdirPin and DdirPin you need to assign a value to them, such as "RdirPin := 1". Is this what you want to do?

    Now for DmotorPin and RmotorPin you are assigning values to them depending on the values of mode and directionFlag. However, you are also calling low(DmotorPin) and low(RmotorPin), which doesn't make sense. DmotorPin and RmotorPins can have values of 75, 100, 150, 200 and 250, which don't correspond to pin numbers. Pin numbers should be between 0 and 31. Calling the low routine with a value greater than 31 doesn't make any sense.
  • Dave HeinDave Hein Posts: 6,347
    edited 2020-08-22 01:44
    bbrien, I read through this entire thread, and I now have a better understanding what you're trying to do. I modified s1m.spin, and attached the new version as s2m.spin. I removed the calls to low(RdirPin), high(RdirPin), and all the other similar calls to low/high that didn't make sense. I believe what you were actually trying to do was to set these values to 0 or 1. I added the code to do that, and I believe the program is sending the correct values now.

    I also moved recvSerialData to it's own cog, so that it simulates a second Propeller chip receiving the data. In your final code you should move recvSerialData to the program for the other Propeller so that is can correctly receive the data from the hand controller. I added a sync byte with a value of 255, so that the receiving Propeller will stay in sync with the hand controller.

    I thought about completely rewriting your program so it would be more compact and efficient. However, I decided to make as few changes as possible to your program because I think this will make it easier for you to understand it. Let me know if this works for you, and if you have any questions.

    Look for these comments to find the changes I made:
    ' Set RdirPin to 1 if east or DdirPin to 1 if south
    ' Clear RmotorPin and DmotorPin for reset condition
    ' Receiver Code
  • bbrienbbrien Posts: 561
    edited 2020-08-22 03:35
    High and low are the same as saying 1 or 0 High is 1 and when I read a high or 1 on RdirPin , that pin should be 3.3v and sets the direction pin east or south.
    1152 x 864 - 386K
    1152 x 864 - 330K
  • Dave HeinDave Hein Posts: 6,347
    edited 2020-08-22 11:46
    Yes, but the value of RdirPin cannot be set by simply calling high(RdirPin). That just puts 3.3v on the pin corresponding to the current value of RdirPin. In your original code RdirPin was never changed, so it remained at a value of zero the whole time. That means that high(RdirPin) was putting 3.3v on pin 0, and low(RdirPin) was putting zero volts on pin 0.

    The program that I posted in s2m.spin is correct. Look at the changes I made, and if you don't understand the changes, ask me about them. Run the program, and you will see that the transmit and received values are correct now.

    EDIT: bbrien, if you still think you are correct, then please tell me what pin are you monitoring when you look for 0v or 3.3v for RdirPin and DdirPin?

    EDIT2: Also, which pins were low(DmotorPin) and low(RmotorPin) driving when their current values were 200?
  • I v'e been running the revised version of the routine on the terminal and they the same as the photo I sent you so every thing is as it should be. the next query regards the "receiver code at the end, does this get added to the t.Mount code(included).
  • It appears that this is the "Telescope mount" file that ChrisGadd posted. You should use it with the "Telescope handbox" program that he also posted. Those two programs work together by sending a single byte containing the two mode bits and four direction switch settings.

    The only thing I might change would be to add an offset of $20 to the byte, which would make it a viewable ASCII character. You would have to subtract the offset in the mount program. This would help with debugging. I tried this on the mount program, where I had it read from the console instead of from the handbox serial port. This way I could type in single letters to see what the program does.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2020-08-23 13:35
    @dave hein - even when it was all done for him and at least once by myself and once also by Bob, he couldn't make a ready to run binary work, although he didn't really try, as if it were deliberate. Maybe he just likes all the attention. He sure has been getting lots of attention. Not no more by me.
  • Yes, I know. I tried helping him back in January, and I gave up trying after a couple of weeks. I'm sure that your code and Bob's would have worked, but I think bbrien had trouble understanding it. I'll have to admit, I had some trouble myself. I like the look of ChrisGadd's code, and I think that bbrien has a chance of getting it to work.
  • That's why I gave him the one binary that he could load on both the same, that would automatically configure and flash LEDs at him and everything. He seemed determined to only load it on one unit and it wouldn't work. Duh. Seemed to insist that I never told him it was 10MHz (automatically selects 5/10) and summarily pulled the plug with no further effort.
  • I tried the telescope hand box version with the Mount version but it was incomplete That is why I wanted to convert the C version to spin. Am going to experiment now with the receiver codes . Will let you know how it turns out .
  • bbrien, I think the switch and serial drivers in the handbox program are complete. The serial portion in the mount program also looks complete, but I can't vouch for the motor drivers. I'll look at it, and maybe add some debug code to it.

    I think there might be a problem with the way you are testing the code. I'm assuming you are loading the code correctly, but it's not working the way you want it to, or at all. You're treating the code as black boxes, and you have no idea why it's not working. I'll see if I can add more debug prints to help you diagnose the problem.

    As I mentioned in my previous post, with a slight adjustment to the serial byte that is transmitted you can test the handbox and mount programs independently. You can use the debug console to enter byte codes manually. I'll make the changes and post the two modified programs.
  • I don't know how to use the console properly but the hand controller appears to be working properly. the buttons on the mount unit make the motors run properly but the program will always output a pulse on the R.A. motor there may be a competition for control of the outputs.
    I added the receive codes to the routine in the mount codes but I get an error "expected an instruction or a variable".please check the new code.
  • I'll take a look at your modifications. However, I've been adding debug prints to ChrisGadd's original files, and I'd like to pursue that also.

    I do have a question. On the handbox, are the switch outputs normally high, or normally low? That is, when you push a button does the pin go low, or does it go high? I noticed that your C code assumed that it went from high to low. ChrisGadd's code assumes low to high. Maybe that's why you can't get it to work with his code.
  • bbrien, can you try these two handbox programs, and tell me which one works correctly? The console debug port is set for 115200 baud. The console should print every time you push one of the direction buttons. It will show the byte code that is sent, the mode value and the direction. Let me know which one works correctly.
  • In the original setup they were wired high and pulled low.The pins are wired low(10k To ground), and the switches send a high(3.3v).
  • Dave HeinDave Hein Posts: 6,347
    edited 2020-08-23 21:04
    OK, so "Telescope handbox dh1.spin" should work correctly then. I have made a version of the mount program that is compatible with this handbox program. It is in "Telescope mount dh4.spin", which is attached below. This version will accept input from either the hand box, or from the console. To test it with the console type the 0, 1, 2, 4 or 8 keys. This will signal that none, north, south, west or east buttons are pressed with a mode value of 0. For a mode value of 1 you would press @, A, B, D or H. For a mode value of 2 press P, Q, R, T or X. For a mode value of 3 press `, a, b, d or h.

    You can press other keys to indicate that multiple buttons are pressed. The full set of codes is in the attached buttons.txt file.

    BTW, I'm still looking at the "Telescope5 Mount.spin" program that you posted, but please try the other files that I posted in the meantime.
  • Telescope handbox dh1 does in fact work and I get alpha column 1 and a number in co.2 and a direction in 3.
  • That's great! Have you tried running Telescope mount dh4, and connecting the handbox to the mount?
  • Yes I have but no readings on the monitor.
  • Did you try typing a key on the keyboard? You should have gotten something on the monitor. The serial port for the console monitor is set 115200 baud.
  • bbrien, can you try this version of the mount program. It prints "Test" once per second on the console monitor. Also try typing the "1" key. It should print "1 0 North" on the monitor. If you're not getting this, then you don't have the Propeller Serial Terminal set up correctly. The baud rate should be 115200, the com port should match the port number that the Propeller tool is using to download the program when you hit F10. Make sure the "Enable" button is not flashing on the PST window. The button should show "Disable" when it is connected to the Prop.
  • Mr. Jakacki you are correct sir. I think we are all getting the run around by the OP.
  • FIRST QUERY ;I did use the keyboard now and the motors will run but the terminal quits responding if you hold down the key.
    I guess it's not supposed to read the auto pins but that's fine because I can watch the motors.
  • Ok it is sending out a 'test' every second and if I hit a button on the keyboard I get a charachter ,0.and direction(s) but no response from the master (s2m)
  • Sounds like you are making progress. For now, we should forget about using s2m, unless you would prefer using code derived from your C program. If you want to use the Spin code derived from your C code we'll have to change the sendSerialData routine to make it compatible with the latest mount code.

    I would suggest using "Telescope handbox dh1" and "Telescope mount dh4", and we can make fixes to those programs. Can you try running those two together?

    I'll look at the mount program and see why the terminal quits running when holding down the key. I'll also see about adding more debug prints, such as when signals from the auto pins are detected.
  • Dave HeinDave Hein Posts: 6,347
    edited 2020-08-24 23:51
    It looks like the problem with the terminal hanging is something in the Parallax Serial Terminal program. If I hold down a key for several seconds PST will quit responding. I tried entering lots of single key strokes for about a minute, and it didn't have a problem.

    I added a debug print of the auto pins whenever they change. I also print the auto pin values every 10 seconds, along with the elapsed time since the program started running.

    Use the attached "Telescope mount dh7.spin" to get the latest changes.
  • bbrienbbrien Posts: 561
    edited 2020-08-29 03:26
    Ok Dave;I am using Hand Box dh1 and just started up the Telescope mount dh7 and I get a count every 10 seconds starting at 40 secs and next line is "auto none" if I press the auto-west I get no reaction but if I press auto-North I get an "auto west". All other directions produce no reactions. No inputs appear from the other Prop(hand box).
  • Ok, here's what I am Thinking, we have at least two cogs running where one is using the four primary output pins and the second cog is receiving the serial data from the other prop. and unable to send to the output pins. I want to test for the presence of the data,pause the cog0 and send the data and when there is no longer any data in the buffer, resume cog0. Can you show me this.
Sign In or Register to comment.