n-wach / camino Goto Github PK
View Code? Open in Web Editor NEWA library for controlling an Arduino from Python over Serial
License: MIT License
A library for controlling an Arduino from Python over Serial
License: MIT License
Hey Nathan, One more item. This happens each time when connecting. I am running with the latest library.
Callable added: get_nth_call
Got error on attempt 1/3: Nothing sent when a response was expected.
Thanks. Please let me know and I will test.
When using camino
from windows, the Serial.set_input_flow_control
method doesn't exist. This means windows users cannot use the package as is.
Although I dont think any of these are used, other platform-specific methods to watch out for are:
nonblocking()
fileno()
set_output_flow_control()
cancel_read()
cancel_write()
Nathan, Nice work.
So question, line number 397 in Camino.cpp was this:
int value = digitalRead(dataArray[0]);
and I was getting only 1 byte values.
I changed it to analogRead:
int value = analogRead(dataArray[0]);
and now I am getting 0-65535 for 0-5V.
That's what you intended right?
I am on a Mega2560.
Thanks. Again, nice work.
Analog reads is returning values 0-65535 (in increments of 257?) when it should be returning 0-1023.
Can you take a look? I can test?
void _analogRead(byte dataLength, byte *dataArray) {
int value = analogRead(dataArray[0]);
byte arr[2] = {(byte) (value % 256), (byte) value};
returns(2, arr);
}
Thanks
Dear all, I am having trouble in trying to use the library in Arduino Due boards.
Is it possible to use it with DUE boards?
See my error message below.
Arduino: 1.8.19 (Linux), Board: "Arduino Due (Programming Port)"
In file included from /home/allison/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino/wiring_private.h:33:0,
from /home/allison/Arduino/libraries/Camino/src/Camino.cpp:1:
/home/allison/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/stdlib.h:67:5: error: expected unqualified-id before 'int'
int _EXFUN(abs,(int));
^
/home/allison/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/stdlib.h:67:5: error: expected ')' before 'int'
/home/allison/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/stdlib.h:67:5: error: expected ')' before 'int'
/home/allison/Arduino/libraries/Camino/src/Camino.cpp: In member function 'void Camino::begin(long int, byte)':
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:20:29: error: 'UCSR0A' was not declared in this scope
#define UCSRNA UCSR0A
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:160:3: note: in expansion of macro 'UCSRNA'
UCSRNA = 1 << U2XN; // enable double rate (2X flag)
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:23:29: error: 'U2X0' was not declared in this scope
#define U2XN U2X0
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:160:17: note: in expansion of macro 'U2XN'
UCSRNA = 1 << U2XN; // enable double rate (2X flag)
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:24:29: error: 'UBRR0H' was not declared in this scope
#define UBRRNH UBRR0H
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:161:3: note: in expansion of macro 'UBRRNH'
UBRRNH = clockRate >> 8;
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:25:29: error: 'UBRR0L' was not declared in this scope
#define UBRRNL UBRR0L
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:162:3: note: in expansion of macro 'UBRRNL'
UBRRNL = clockRate & 0xff;
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:22:29: error: 'UCSR0C' was not declared in this scope
#define UCSRNC UCSR0C
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:165:3: note: in expansion of macro 'UCSRNC'
UCSRNC = 0x06;
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:21:29: error: 'UCSR0B' was not declared in this scope
#define UCSRNB UCSR0B
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:168:7: note: in expansion of macro 'UCSRNB'
sbi(UCSRNB, RXENN);
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:26:29: error: 'RXEN0' was not declared in this scope
#define RXENN RXEN0
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:168:15: note: in expansion of macro 'RXENN'
sbi(UCSRNB, RXENN);
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:168:20: error: 'sbi' was not declared in this scope
sbi(UCSRNB, RXENN);
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:27:29: error: 'TXEN0' was not declared in this scope
#define TXENN TXEN0
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:169:15: note: in expansion of macro 'TXENN'
sbi(UCSRNB, TXENN);
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:28:29: error: 'RXCIE0' was not declared in this scope
#define RXCIEN RXCIE0
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:172:15: note: in expansion of macro 'RXCIEN'
sbi(UCSRNB, RXCIEN);
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp: In member function 'void Camino::sendResponsePacket()':
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:36:29: error: 'UDR0' was not declared in this scope
#define UDRN UDR0
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:224:3: note: in expansion of macro 'UDRN'
UDRN = packetArray[packetTransmitIdx];
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:21:29: error: 'UCSR0B' was not declared in this scope
#define UCSRNB UCSR0B
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:228:7: note: in expansion of macro 'UCSRNB'
sbi(UCSRNB, UDRIEN);
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:37:29: error: 'UDRIE0' was not declared in this scope
#define UDRIEN UDRIE0
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:228:15: note: in expansion of macro 'UDRIEN'
sbi(UCSRNB, UDRIEN);
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:228:21: error: 'sbi' was not declared in this scope
sbi(UCSRNB, UDRIEN);
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp: In function 'void USART0_RX_vect()':
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:36:29: error: 'UDR0' was not declared in this scope
#define UDRN UDR0
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:265:7: note: in expansion of macro 'UDRN'
c = UDRN;
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp: In function 'void USART0_UDRE_vect()':
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:21:29: error: 'UCSR0B' was not declared in this scope
#define UCSRNB UCSR0B
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:352:9: note: in expansion of macro 'UCSRNB'
cbi(UCSRNB, UDRIEN);
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:37:29: error: 'UDRIE0' was not declared in this scope
#define UDRIEN UDRIE0
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:352:17: note: in expansion of macro 'UDRIEN'
cbi(UCSRNB, UDRIEN);
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:352:23: error: 'cbi' was not declared in this scope
cbi(UCSRNB, UDRIEN);
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:36:29: error: 'UDR0' was not declared in this scope
#define UDRN UDR0
^
/home/allison/Arduino/libraries/Camino/src/Camino.cpp:359:3: note: in expansion of macro 'UDRN'
UDRN = packetArray[packetTransmitIdx];
^
exit status 1
Error compiling for board Arduino Due (Programming Port).
Hello,
While using this library in conjunction with an Arduino Mega 2560, the following warnings are given during compilation:
'USART_RX_vect' appears to be a misspelled 'signal' handler, missing '__vector' prefix [-Wmisspelled-isr]
'USART_UDRE_vect' appears to be a misspelled 'signal' handler, missing '__vector' prefix [-Wmisspelled-isr]
It seems that despite the comment on lines 29&30 of Camino.cpp,
i.e.
29 #define USARTN_RX_vect USART_RX_vect // no number for some reason
30 #define USARTN_UDRE_vect USART_UDRE_vect // no number for some reason
The ATmega2560 does in fact use a numbering convention (source).
For the ATmega2560 Port 0 should be:
#define USARTN_RX_vect USART0_RX_vect // for some AT devices, there is no number.
#define USARTN_UDRE_vect USART0_UDRE_vect // for some AT devices, there is no number.
Without this change obviously Atmega2560 won't respond to requests:
Callable added: num_calls
Callable added: get_nth_call
Got error on attempt 1/3: Nothing sent when a response was expected.
Got error on attempt 2/3: Nothing sent when a response was expected.
Got error on attempt 3/3: Nothing sent when a response was expected.
Traceback (most recent call last):
File "/camino.py", line 100, in send_command
response = self.read_packet()
File "/camino.py", line 39, in read_packet
header_byte_1 = self.read_byte()
File "/camino.py", line 34, in read_byte
raise CaminoException(
camino.CaminoException: Nothing sent when a response was expected.
Hope this helps!
Hey Nathan,
Starting line 393 in Camino.cpp, analog write only accepts a value between 0-254. Shouldn't the write value be dataArray[1]. It seems to work when I test.
Analog read is 10 bit, 0-1023
Analog write is 0-255
void _analogWrite(byte dataLength, byte *dataArray) {
// analogWrite(dataArray[0], dataArray[1]*256 + dataArray[2]); // was this
analogWrite(dataArray[0], dataArray[1]); // Should be this?
}
Thanks
It looks like each communication takes 50 ms. Is that what you see? Any way to speed that up? Here is the Python code. I am on an Arduino MEGA 2560 at 115200 baud with your default ino file and just the baud rate changed.
while(1):
n = n + 1
tms = time.time() * 1000
arduino.digital_read(9) # 50 ms
arduino.say_hi(16, out=str) # 50 ms
a0 = arduino.analog_read(0, out=int) # 50 ms
arduino.pin_mode(16, 1) # 50 ms
time.sleep(.005) # add 5 ms
tms = time.time() * 1000 - tms
print('n =', n, 'mills =', int(tms))
Thanks for sharing the code and your help.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.