kumarsivarajan / chemshapes

Automatically exported from code.google.com/p/chemshapes
0 stars 0 forks source link

Add CS1 Host support for Arduino board type auto-detection (mega 2560 and 1280) #13

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Arduino MEGA 1280 can not be connected with CS1 host in Linux.
It is possible with MEGA 2560.on both boardfs i have the same firmware.

after copiling CS1 with 1280 connected ther is no device shown in the "Serial 
Port" frame.

dmesg | tail for MEGA 1280 says:
**********************
[ 1778.229420] usb 7-1: new full-speed USB device number 5 using uhci_hcd
[ 1778.430127] ftdi_sio 7-1:1.0: FTDI USB Serial Device converter detected
[ 1778.430153] usb 7-1: Detected FT232RL
[ 1778.430155] usb 7-1: Number of endpoints 2
[ 1778.430157] usb 7-1: Endpoint 1 MaxPacketSize 64
[ 1778.430159] usb 7-1: Endpoint 2 MaxPacketSize 64
[ 1778.430161] usb 7-1: Setting MaxPacketSize 64
[ 1778.432111] usb 7-1: FTDI USB Serial Device converter now attached to ttyUSB0
**********************

when Pressing "Connect" in CS1 the following appears:
************************************************************************
.....
/home/martin/chemshapes/host/glViewport/slicer.vert
Opening serial port: 
Traceback (most recent call last):

  File "./draft.py", line 170, in <lambda>

self.connect(self.ui.findChild(QToolButton, 'connect') , SIGNAL('clicked()'), 
lambda: self.connectButton() )

  File "./draft.py", line 443, in connectButton

self.arduinoException()

  File "./draft.py", line 404, in arduinoException

self.disconnect()

TypeError
: 
arguments did not match any overloaded call:
  QObject.disconnect(QObject, SIGNAL(), QObject, SLOT()): not enough arguments
  QObject.disconnect(QObject, SIGNAL(), callable): not enough arguments
********************************************************************

What steps will reproduce the problem?
1. Connect an Arduino Mega 1280 to the Host-Computer
2. Compile CS1 with make
3. Press "connect" in CS1

System specifications were the error occur?
  Operational System: Ubuntu 12.04 AMD64
  Video Board Model: Ati HD 4890

Original issue reported on code.google.com by designpr...@googlemail.com on 3 May 2012 at 12:26

GoogleCodeExporter commented 8 years ago
This is because The CS1 Host software only looks for the ACM prefix. I need to 
add a check for USB prefix as well. That should fix it!

Original comment by hra...@gmail.com on 4 May 2012 at 6:09

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
OK. got it to work by adding following lines in __init__.py . beneath the line 
122 i added the following lines:       
            try:
                com = "/dev/ttyUSB%d" % each
                if 'win' in sys.platform:
                    com = "COM%d:"% each
                serial.Serial(com)
                self.comList[com] = com
            except:
               pass

Of course as i am not a coder i dont know if this could make a new problem. but 
for now it seams to work with both (MEGA 1280 and MEGA 2560). Hope that u can 
use this

Best greets

Martin

Original comment by designpr...@googlemail.com on 10 May 2012 at 8:46

Attachments:

GoogleCodeExporter commented 8 years ago
I tried to upload firmware to the MEGA1280 with the "Upload Firmware" Botton 
but got timeout errors.

researched a bit in the net and fond a solution: 

the arguments for avrdude had to be changed to the following:
'avrdude -D -C firmware/avrdude/avrdude.conf -q -p atmega1280 -P %s -c arduino 
-b 57600 -U flash:w:firmware/bin/firmware.hex:i'

then of course the upload to Mega2560 didnt work any more. so i added an if 
...: else ...: action to checkout what kind of Board is connected.

The final result looks like:
def uploadFirmwareAction(self):
        self.currentCom = str(self.coms.currentText())
        self.disconnectSerial()

        if 'win' in sys.platform:
            avrdudePath = os.path.join( 'firmware', 'avrdude', 'win32' )
            avrdudeCfg  = os.path.join( 'firmware', 'avrdude', 'win32','avrdude.conf' )
            avrdude     = os.path.join( avrdudePath, 'avrdude.exe' )
            os.environ['PATH'] = "%s;%s" % ( avrdudePath, os.environ['PATH'] )
            if os.system('%s -D -C %s -q -p atmega2560 -P %s -c stk500v2 -b 115200 -U flash:w:firmware/bin/firmware.hex:i' % (avrdude, avrdudeCfg, self.currentCom) ):
                raise Exception("Error uploading firmware to arduino.")
        else:
            if '/dev/ttyUSB' in self.currentCom:
                if os.system('avrdude -D -C firmware/avrdude/avrdude.conf -q -p atmega1280 -P %s -c arduino -b 57600 -U flash:w:firmware/bin/firmware.hex:i' % self.currentCom ):
                    raise Exception("Error uploading firmware to arduino.")
            else:
                if os.system('avrdude -D -C firmware/avrdude/avrdude.conf -q -p atmega2560 -P %s -c stk500v2 -b 115200 -U flash:w:firmware/bin/firmware.hex:i' % self.currentCom ):
                    raise Exception("Error uploading firmware to arduino.")

        self.connectButton()

at the research in the net i found a little type-error mistake in your code.
-cstk500v2 should be -c stk500v2
i changed that too in the windows-upload-firmware-action-code-snipped but dont 
know how to test it because i dont know how to compile CS1 in linux for 
windows. and of course i dont know how to implement the 2560/1280 checking in 
the windows-upload-firmware-action-code-snippet. but i will try to find out now.

Original comment by designpr...@googlemail.com on 11 May 2012 at 9:08

Attachments:

GoogleCodeExporter commented 8 years ago
ok got no clue how to check for arduino-boardversion in 
windows-upload-firmware-action-code-snipped.
what i can say is that:

the driver for the mega1280 in windows is from FTDI and is located in 
c:\windows\system32\drivers\ name: "ftser.sys"

the driver for mega2560 in windows is from Arduino LLC and is located in 
c:\windows\system\drivers\ name: "usbser.sys"

maybe a checking for the used driver in the 
windows-upload-firmware-action-code-snipped could do the trick.

on the net i found a good example code for checking the boardversion ( 
http://totaki.com/poesiabinaria/wp-content/uploads/2011/07/sconstruct ).

but i cant implement and try that because as i mentioned above i dont know how 
to compile cs1 for windows in linux. so no chance to test my code in windows or 
wine.

hope this helps!

Best 

Martin

Original comment by designpr...@googlemail.com on 11 May 2012 at 11:09

GoogleCodeExporter commented 8 years ago
Thanks for the help, Martin!!!

The only way I could find to detect the board type is by using avrdude to 
retrieve the signature ID:

    avrdude -c stk500 -p m2560 -P /dev/ttyUSB0 

this command line should return this:

    avrdude: AVR device initialized and ready to accept instructions

    Reading | ############################################### | 100% 0.02s

    avrdude: Device signature = 0x1e9801

0x1e9801 is the device signature for a mega 2560 board.If you run this command 
on your 1280, you'll probably see this:

    avrdude: AVR device initialized and ready to accept instructions

    Reading | ############################################### | 100% 0.02s

    avrdude: Device signature = 0x1e9703
    avrdude: Expected signature for ATMEGA2560 is 1E 98 01
                 Double check chip, or use -F to override this check.

As you can see, it retreives the device ID of your board, which can give a clue 
to the host of WHAT board type you have an what command line to use! ;)

It's kinda "hacky" way to detect, but it should work for this cases. 

I'll add this check to the main host trunk asap. 

thanks for the contribution, Martin... really appreciate!!

-H

Original comment by hra...@gmail.com on 31 May 2012 at 9:01

GoogleCodeExporter commented 8 years ago

Original comment by hra...@gmail.com on 31 May 2012 at 9:02