cosmic-pi-deprecated / cosmicpi-daq

Data acquisition package for reading data from an Arduino via USB serial on a Raspberry Pi
6 stars 3 forks source link

Stop serial connection resetting the Arduino board #16

Closed quixoft closed 8 years ago

quixoft commented 8 years ago

The serial connect resets the Arduino causing the breakout boards to die. Please edit the init method of the keyboard file init method as follows class KeyBoard(object): def init(self): self.fd = sys.stdin.fileno()

    # Stop resetting the Arduino on serial connect, it kills the breakouts
    self.newattr = termios.tcgetattr(self.fd)
    self.newattr[2] = self.newattr[2] & ~termios.HUPCL
    termios.tcsetattr(self.fd, termios.TCSANOW, self.newattr)

pingud98 commented 8 years ago

Seems sensible!

We could also implement this in hardware, which we've done previously whilst prototyping to prevent recycling the HV. It does require you to press the button when flashing the firmware though. Software, rather than firmware is definitely better.

Edit: as Topaz replied, there is a much easier way to disable auto reset: put a 1K resistor between reset and 3V3. Nevertheless the firmware mod described here has the convenience that it disables auto reset while auto upload still works. – And it is good fun too!

I stole if from this blog, which seems pretty good. https://petervanhoyweghen.wordpress.com/2013/05/04/disabling-auto-reset-on-the-due/

On 13 May 2016 at 19:46, Julian Lewis notifications@github.com wrote:

The serial connect resets the Arduino causing the breakout boards to die. Please edit the init method of the keyboard file init method as follows

class KeyBoard(object): def init(self): self.fd = sys.stdin.fileno()

Stop resetting the Arduino on serial connect, it kills the breakouts

self.newattr = termios.tcgetattr(self.fd) self.newattr[3] = self.newattr[3] & ~termios.HUPCL termios.tcsetattr(self.fd, termios.TCSANOW, self.newattr)

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/CosmicPi/cosmicpi-daq/issues/16

quixoft commented 8 years ago

Yes it's very annoying because I loose the HTU and 10-DOF boards after a serial line reconnect. The only way to get them back is via a power on/off/on cycle and then restart the sketch. I have posted on the forums to see if anyone else is having this problem. I have to get to the bottom of this. The hardware solution sounds like a bit of a kludge, I also heard people connecting 10uf between the dessert and ground.

quixoft commented 8 years ago

Reset not dessert

On Fri, May 13, 2016, 23:36 Julian Lewis lewis.julian@gmail.com wrote:

Yes it's very annoying because I loose the HTU and 10-DOF boards after a serial line reconnect. The only way to get them back is via a power on/off/on cycle and then restart the sketch. I have posted on the forums to see if anyone else is having this problem. I have to get to the bottom of this. The hardware solution sounds like a bit of a kludge, I also heard people connecting 10uf between the dessert and ground.

On Fri, May 13, 2016, 23:30 James Devine notifications@github.com wrote:

Seems sensible!

We could also implement this in hardware, which we've done previously whilst prototyping to prevent recycling the HV. It does require you to press the button when flashing the firmware though. Software, rather than firmware is definitely better.

Edit: as Topaz replied, there is a much easier way to disable auto reset: put a 1K resistor between reset and 3V3. Nevertheless the firmware mod described here has the convenience that it disables auto reset while auto upload still works. – And it is good fun too!

I stole if from this blog, which seems pretty good.

https://petervanhoyweghen.wordpress.com/2013/05/04/disabling-auto-reset-on-the-due/

On 13 May 2016 at 19:46, Julian Lewis notifications@github.com wrote:

The serial connect resets the Arduino causing the breakout boards to die. Please edit the init method of the keyboard file init method as follows

class KeyBoard(object): def init(self): self.fd = sys.stdin.fileno()

Stop resetting the Arduino on serial connect, it kills the breakouts

self.newattr = termios.tcgetattr(self.fd) self.newattr[3] = self.newattr[3] & ~termios.HUPCL termios.tcsetattr(self.fd, termios.TCSANOW, self.newattr)

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/CosmicPi/cosmicpi-daq/issues/16

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/CosmicPi/cosmicpi-daq/issues/16#issuecomment-219164174

Julian Lewis Mobile: +33646447515

Julian Lewis Mobile: +33646447515

jlsalmon commented 8 years ago

Question: doesn't the KeyBoard class only modify the tty attributes of stdin? Would removing HUPCL from stdin have any effect on the Arduino reset? Shouldn't it be removed on the serial device instead? Something like:

usbdev = options.usbdev
attrs = termios.tcgetattr(usbdev)
attrs[2] = attrs[2] & ~termios.HUPCL
termios.tcsetattr(usbdev, termios.TCSAFLUSH, attrs)
ser = serial.Serial(port=usbdev, baudrate=9600, timeout=60)

Found via this post. Maybe I'm talking bullshit and my understanding of how TTYs work isn't up to scratch.

quixoft commented 8 years ago

No the there are many fields in term in, input, output, control, local and speed. I am operating on /dev/ttyUSB. But there may be a point I what you are saying, it's worth me taking a further look. Don't do anything yet. Just to let you know there are at least three problems to be solved, the first is to understand why the serial link hangs, the second how to avoid reset when it is reconnected, and the big one, why do the breakout boards for the HTU and 10-DOF become unreachable, to get them back I have to off/on the power. So some problems to solve here....So ignore the issue for the time being, I need to do more research, thanks for the link.

On Sat, May 14, 2016, 13:02 Justin Lewis Salmon notifications@github.com wrote:

quixoft commented 8 years ago

Termio not term in

quixoft commented 8 years ago

Shit, sorry yes I was on the wrong device, Sorry Justin you were correct. For some reason I modded the keyboard input not the USB - I must be crazy. When I read your comment I thought you were talking about termio fields - argh - So my mod was complete bullshit. What I will do is mod the file test it and push it to my branch - then you can have a look. Thanks for spotting my stupid mistake