Go Down

Topic: Dynamically get the model of Arduino (Read 2629 times) previous topic - next topic

Horacio

The largest pin with PWM support is pin 13 on Arduino Mega... 16 bits will work ok, until some Arduino board implements support of PWM on a pin larger than 15, but I'd be easy to change.

I've added the struct to PyArduinoProxy, it's working great!. I've kept the information I need to do the validation... From the linux shell:

Code: [Select]

$ ./examples/arduino_type.py /dev/ttyACM0
CPU: ATmega328P
{'analog_pins': 6,
'digital_pins': 14,
'eeprom_size': 1,
'flash_size': 32,
'pwm_pins_bitmap': '111001101000'}


From a python program:

Code: [Select]

proxy.getAvrCpuType() -> to get the CPU type
proxy.getArduinoTypeStruct() -> to get a dictionary with the info of arduino_type


Here can see the source code https://github.com/hgdeoro/py-arduino-proxy/blob/master/src-c/arduino_type.h.

Again, thank you!!

robtillaart

#16
May 19, 2011, 04:58 pm Last Edit: May 19, 2011, 05:10 pm by robtillaart Reason: 1
Have you tested in under win7 too?

Q: why did you remove parts from the .h file?
I can imagine it is not used in your app but it makes the concept less usable, and it will take only a few extra bytes?

(no hard feelings, just want to keep the idea useable for as many apps as possible).
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Horacio

Nop... I haven't tested in any versions on Win (I don't even know how to specify a serial port in Windows from Python)... I you are interested, I could try to make it work on Windows XP (once workig on XP, it should work on 7 too). I think this shouldn't be so difficult...

robtillaart

Is the python script also on git?

Serial in python should be platform independant (OK download the right py_serial)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Horacio

Yes, everything is on github:
1) all the python code (ArduinoProxy) - on the src directory.
2) a pre-generated sketch (on the pde directory).
3) on the scripts all test cases and the scripts to re-generate the sketch (for facilitate the creation of your own methods, and re-generate the sketch for support of optionales componentes, currently: support for LCD display). Currently, these scripts are shell script, highly tighted to Linux shell.

Senso

How about using the #elif defined (__AVR_ATmega2560__) blocks and just add code and let the compiler sort what should be included or not?
You will not put the .hex from an Atmega328 in an Atmega2560, at least if you are the casual Arduino user you use the IDE so you choose which board/processor you have, so why spend flash and ram in useless things that the compiler can sort for you?

Horacio

I think it's easier to do the validation in Python, and the general performance would be better. Since validation is done in Python, you can detect the errors and raise exception, avoiding the communication to the Arduino. And adding support for a new board is easier with the current schema (one board = add 1 line in 1 file), something like:

Code: [Select]

this_arduino_type = { 6, 14, 1<<3 | 1<<5 | 1<<6 | 1<<9 | 1<<10 | 1<<11, 1, 32 }; // Arduino UNO


Anyway, I'll give your idea some thoughts, I found it as an interesting alternative, and performance improvements are always welcome!
Thanks!

Horacio


Have you tested in under win7 too?

Q: why did you remove parts from the .h file?
I can imagine it is not used in your app but it makes the concept less usable, and it will take only a few extra bytes?

(no hard feelings, just want to keep the idea useable for as many apps as possible).


I've tried make it work on window xp without success. Installed Python 2.7 and PySerial, installed Arduino drivers, but got an 'Access is denied' error when trying to open com3...

About the removed parts, that's because I don't need it for validation... but you're right, maybe would be better to have it... I don't need it for validation, but for someone else may be necessary. I've tried to put the struct in flash memory (using PROGMEM), so no ram memory is wasted and to put back the removed fields, but couldn't make it work... I'll try again in some days, after investigating a little more about PROGMEM. I've uploaded the non-working code to a different git branch (I put in master only the working code)... In case you are interested, it's at:

https://github.com/hgdeoro/py-arduino-proxy/blob/666db4ff8bca3e25c673997c5abe298a74b30db9/src-c/arduino_type.h#L49
https://github.com/hgdeoro/py-arduino-proxy/blob/666db4ff8bca3e25c673997c5abe298a74b30db9/src/arduino_proxy/proxy.py#L1090

The code compiles, but proxy.getArduinoTypeStruct() returns invalid values for the structs elements (analog_pins, digital_pins, etc.)


Horacio


Have you tested in under win7 too?


I finally could make it work on XP. I've also made a web interface (see the wiki page: https://github.com/hgdeoro/py-arduino-proxy/wiki/Web-Interface). To make the web interface work on Windowns, install Python, install PySerial, download Py-Arduino-Proxy and execute the webserver.py (it's in the bin directory).


http://www.youtube.com/watch?v=QE6UJSs3b6Q


Go Up