Wireless speedometer Project

Discussion in 'The Projects Forum' started by cretcheu, Apr 16, 2012.

  1. cretcheu

    Thread Starter New Member

    Apr 16, 2012
    8
    0
    I am using a Yellowjacket microcontroller, it is an arduino clone with Wifi capabiliies. The arduino IDE sees it as an Arduino Uno. I have modified the socket app to provide an adhoc peer-to-peer connection between the controller and an iPhone.
    The microcontroller accepts pulses from a read sensor and on each pulse sends a "1" over Wifi to the iPhone which calculates the speed and displays it.
    The problem that I am having is that the YJ appears to pause periodically for couple of seconds causing the speed to fluctuate wildly. It appears that something is blocking the transmission and packet are lost.

    here is a code snippet:

    void setup()
    {
    pinMode(sensorPin, INPUT);
    digitalWrite(sensorPin, HIGH);
    WiFi.init();
    }
    void loop()
    {
    WiFi.run();


    }

    static int handle_connection(struct socket_app_state *s)
    {
    PSOCK_BEGIN(&s->p);

    while(UIP_CONNECTED) {

    sensorState = digitalRead(sensorPin);

    if (sensorState == 0) {
    pulse = 1;
    } else {
    pulse =0;
    }

    if (pulse == 1) {
    PSOCK_SEND_STR(&s->p, "1");
    }

    }
    PSOCK_CLOSE(&s->p);
    PSOCK_END(&s->p);
    }
     
  2. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    please remember to use code brackets in future posts (welcome to AAC by the way) the code tags are the little # button at the top of the reply box =]
    have you tried removing some of the functionality?
    i.e.: set an led high at the beginning, and set it low at the end, measure with an oscilloscope and see if the time of the loop changes?
    i have used this method before for an interrupt issue i was having.
     
  3. cretcheu

    Thread Starter New Member

    Apr 16, 2012
    8
    0
    Thanks for the welcome and the tip on code tags...
    Unfortunately, I don't know what I don't know. I have pretty much confirmed that the YJ Wifi transmissions are being interrupted but I am not a microcontroller C programmer. The socketapp that I modified uses a number of library files that I am clueless about, so I have no idea where to look for the blocking.
    I am guessing that the main run loop gets executed only once since once a connection is established the code remains in the While loop. Could that be a problem? Tried to combine the two but the main loop is in the .pde file and the While loop is in the associated .c file.
     
  4. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    what about this:
    the loop() will call your function, which has the while(device connected).
    if you have a spare led, try turning it on at the beginning of loop()... or toggling it? i was going to suggest turning it off at the end of loop() but ill explain why not now..
    i suggest this because your loop() is so small if it comes back into loop() it will cycle through so quickly you wont notice any real change..
    my feeling is, you should check if its losing connection, potentially, your device could be becoming "detached" enough to lose one cycle.. maybe more.. and that causes loss of signal.
    i might be wrong.. but you can prove it.. toggling the led..
    not sure if you can do digitalWrite(xpin,!xpin) style thing.. so it will invert it, failing that youll just have to use an if statement.. if xpin high set low.. if low set high :) that way you know (if you set it high initially.. because then itll turn it off on entering loop() whether it comes back into loop..
     
  5. cretcheu

    Thread Starter New Member

    Apr 16, 2012
    8
    0
    Thanks,
    Don't have the resources to do as you suggested, however, I did change the While (connected) to While (1) and the problems seems to have gone away. So appears you were correct about the detaching due to momentary loss of connection. That would explain the packets disappearing.
    Now having the opposite problem. At low speeds I get a ton of extra packets. Trying to figure if this is being caused by switch bounce.
    For some reason I cannot include a delay statement, in the code, as a debounce mechanism because it causes a disconnect of the wifi. Any ideas.

    You help is greatly appreciated!
     
  6. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    i would assume that due to the change in that while statement, youre now transmitting every single time.. therefore extra data is being transmitted!:p
    why not try adding some coding? youre currently sending a 1, why not send some additional overhead?
    this way you could sort of modulate your signal into another? so when youre actual signal is being transmitted, thats what you receive at the other end..?
    making this kinda complicated, and not sure how youd go about doing that so gonna have a think about it, but i think that might be the way of solving it..
    think of it like transmitting at 44kHz (for example) and your RPM can go from 1Hz to 44kHz by encoding your data into a byte?:) OO using masking.. that could make everything more difficult.. have a think, let me know if possible with your hardware.. can you post pictures?
     
  7. cretcheu

    Thread Starter New Member

    Apr 16, 2012
    8
    0
    Here is a link to the hardware: http://ruggedcircuits.com/html/yellowjacket.html
    I have attached a picture off my configuration. I only send a "1'" when the pin is set low by the reed switch closing. I could send a "0" when the switch is open but I don't see the value in doing that. I think I need to debounce the switch at slow speed. At running speed it seems to be working better but it is a bit jumpy. I am now averaging 5 seconds of reads in an effort to smooth it out.
    I need more control over packet transmission but I don't understand the UIP protothread tool that I am using to manage the socket. It's a miracle I have gotten this far!
     
    • yj.png
      yj.png
      File size:
      14.1 KB
      Views:
      11
  8. cretcheu

    Thread Starter New Member

    Apr 16, 2012
    8
    0
    Posted a reply yesterday with a diagram of the board and a link to the product data. I must have done something wrong as it has no appeared...
     
  9. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    He means enclosing your code with {code} {/code}
    where instead of { use [ and } becomes ].
     
  10. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    give it another go.. bit odd!
     
  11. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    Guys, this looks like an automotive thread. Is it?
     
  12. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    As an example, there is a wireless tire pressure sensor that transmits data from inside the wheel to a display unit.

    Similarly, this is a remote data transmitter from a sensor to a display unit. I see no harm in discussion RF data transmission and reception using microcontrollers.
     
  13. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    dont think its an old thread Bill. :)
     
  14. cretcheu

    Thread Starter New Member

    Apr 16, 2012
    8
    0
    In response to Bill. No this is not an automotive issue. It is a socket, UIP protothread issue.
    Chris
    The code only sends a "1" when the reed switch is low even though it is looping thru to While so there should be no additional packets unless the switch is bouncing or something else is awry with the socket code.
    Here is a link to the hardware: http://ruggedcircuits.com/html/yellowjacket.html

    I have also attached a diagram of my config
     
    • yj.png
      yj.png
      File size:
      14.1 KB
      Views:
      15
  15. cretcheu

    Thread Starter New Member

    Apr 16, 2012
    8
    0
    Chris,
    Got a message after posting saying will not be posted until moderator reviews it...
    Do not repost. I guess that is what's happened to the first one. I'm assuming this is due to the attachment????
     
  16. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    maybe? what were you uploading? maybe you can upload a jpg?
     
  17. cretcheu

    Thread Starter New Member

    Apr 16, 2012
    8
    0
    It is a .png which it said is an acceptable file type.
    Do you get notified if a post is not accepted by the moderator?
    If I don't see the posts by tomorrow I will try a .jpg
     
  18. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    okidoke! bit odd, never heard of it before =]
     
  19. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    Again, what is the speedometer for?

    You can PM or email me or another moderator the answer, if it passes muster I or they will reopen this thread.
     
    Last edited: Apr 19, 2012
  20. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    After pulling teeth, that it, discussing this with the OP it has been established this is for a bicycle, which is an open subject. Mind reading has never been a skill of mine.
     
    Last edited: Apr 19, 2012
Loading...