Pages: 1 [2]   Go Down
Author Topic: Dynamically get the model of Arduino  (Read 2380 times)
0 Members and 1 Guest are viewing this topic.
Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
$ ./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:
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!!
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13870
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
« Last Edit: May 19, 2011, 10:10:39 am by robtillaart » Logged

Rob Tillaart

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

Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13870
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is the python script also on git?

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

Rob Tillaart

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

Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Portugal
Offline Offline
God Member
*****
Karma: 6
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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!
Logged

Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.)

Logged

Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).




Logged

Pages: 1 [2]   Go Up
Jump to: