IO interface with Arduino over Ethernet

More
11 years 7 months ago - 11 years 7 months ago #56543 by mariusl
I discovered that the receive buffer on the PC side could get flooded due to the fact that the Arduino transmits data without handshaking. It would cause the user component to not be able to address all the messages in the allotted time that it has to compute. As a result of this you could get messages that are delayed for several seconds as they are waiting for the que to be emptied.

The solution is to make the Arduino code only answer when it has received something from the host.
Code:
void loop() { //encodeTx(); // Moved this from here // if there's data available, read a packet int packetSize = Udp.parsePacket(); if(packetSize) { Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE); decodeRx(packetBuffer,packetSize); encodeTx(); // moved to here } long newPosition = myEnc.read(); if (newPosition != oldPosition) { counters[0] = oldPosition; counters[1] = newPosition; oldPosition = newPosition; //Serial.println(newPosition); } //delay(10); }

Regards
Marius


www.bluearccnc.com

Last edit: 11 years 7 months ago by mariusl.
The following user(s) said Thank You: DocStein99

Please Log in or Create an account to join the conversation.

More
9 years 10 months ago #84767 by M4MazakUser
i tried this out yesterday and it works really well. ill hook up an encoder tonight to see if it drops position.
one thing i found was you need to '#' out the following lines in the python code

#import serial
import os
import hal
import sys
import time
import socket # cant remember if i hashed this one as well.
# from gwibber.microblog.can import RECEIVE
# from _socket import SOL_SOCKET
# from IN import SO_BINDTODEVICE
it worked fine after this. -gwibber has been removed from the default debian package list.

please tell me if im doing somthing wierd. im setting up a lathe/ 3d printer/ plasma cutter for myself. and cant really afford the
high cost of mesa cards (aus ---> us exchange rate) ive used them before and they are excellent but uno's are $6 + $12 for an ethernet shield....

Please Log in or Create an account to join the conversation.

More
9 years 10 months ago #84775 by M4MazakUser
Well i tried my 5000ppr encoder on it as a test. And yup it aint fast enough. But my engineering friend who writes arduino code a plenty says it's more than adequate. So i geuss I'll go see him.

Please Log in or Create an account to join the conversation.

More
9 years 8 months ago #87981 by DocStein99
Hi. I found this while searching for a project to make my own WiFi MPG / hardware interface for LinuxCNC. Thank you for providing the information.

I am going over the Arduino code and am a little confused. Before I test the project, I wanted to modify it for my own needs and be certain the code was tidy. There are functions in the code that are a little inefficient, and some code that is executing that probably should not.
Code:
void encodeTx() { Udp.beginPacket(ipRemote, portRemote); uint8_t v = 0; for(int c = 0; c < 6; c++) { adcResult = analogRead(c); sprintf(ReplyBuffer,"%4d", adcResult); Udp.write(ReplyBuffer); Udp.write(","); int dummy = c; if (c >= iOutputPins) { int moredummy = c; if(digitalRead(pinMap[c])){ v |= (1<<c); } } }

This is reading only analog values from pins 0-5, and sends the data out. 1/2 way through the loop, it will read digital input values, and do nothing with them, storing to "V" which is never used.

The decodeRX function also wants to set the pin-modes, after the setup function each and every time it receives a UDP packet. Not sure what the purpose of that was, since it would take some pretty sophisticated hardware to process data that could swap input & output pins at runtime.

Just curious....

Please Log in or Create an account to join the conversation.

More
9 years 8 months ago - 9 years 8 months ago #87986 by mariusl
Have a look at the server side code as well to see that the Arduino is configured on the fly at startup. It does not know the pin type or direction or pullup value when it starts itself. So things seem to bee a bit disjointed if you only look at one side of the code.
There are some files included further up in this thread.

Regards
Marius


www.bluearccnc.com

Last edit: 9 years 8 months ago by mariusl.

Please Log in or Create an account to join the conversation.

More
9 years 8 months ago #87989 by DocStein99
Ok I'm getting the hang of it. I'm having trouble with network transmissions from Arduino to the python script. I can manage to clean up the Arduino code pretty tight, so that it sends the whole packet in one line, instead of spreading across the code causing fragmentation (for reasons unknown - is my first esp8266, and uncertain I soldered the circuits without noise).

I'm trying to go over the python part - and learn that language at the same time, struggling to get print() & debug messages out to the screen. At the moment, is returning an error on that "recv(150)" command.

Please Log in or Create an account to join the conversation.

Time to create page: 0.177 seconds
Powered by Kunena Forum