moddevices / cc-arduino-lib

Arduino library for the Control Chain protocol
6 stars 9 forks source link

Control Chain not working on custom Arduino Uno-like #5

Open Rezzonics opened 3 years ago

Rezzonics commented 3 years ago

I have a custom Arduino Uno-like board with ATMega328P microcontroller, an LCD connected via SPI, several buttons and LEDs (on PD ports). Linux PC with Ubuntu 18.04 connects to ATMega328P UART0 (PD0/1) via USB/UART device CP2104. /dev/ttyUSB0 is detected by PC. Several tests using Arduino generic libraries show that LCD works, buttons and LEDs work and timer works OK. Serial port /dev/ttyUSB0 tests also work at any speed (9600, 115200, 500000). cc-master on latest master version built OK. cc-master test cc-test apparently works OK with the following output: $ controlchaind /dev/ttyUSB0 -f [cc-lib] control chain started (port: /dev/ttyUSB0, baud rate: 115200) RECV: device: 0, command: handshake, data size: 15 data: 07 61 72 64 75 69 6E 6F B0 CA 01 00 02 03 04 text: arduino

[cc-lib] handshake received [cc-lib] random id: 51888 [cc-lib] protocol: v1.0 [cc-lib] firmware: v1.0.0 SEND: device: 0, command: handshake, data size: 4 data: B0 CA 01 01 text:

SEND: device: 1, command: device descriptor, data size: 1 data: 00 text:

RECV: device: 1, command: device descriptor, data size: 28 data: 04 54 45 53 54 02 01 04 41 43 54 31 03 00 00 00 01 02 04 41 43 54 32 03 00 00 00 01 text: TESTACT1ACT2

[cc-lib] device descriptor received [cc-lib] id: 1, uri: TEST [cc-lib] label:  [cc-lib] channel: 0 [cc-lib] actuators count: 65 SEND: device: 1, command: device descriptor, data size: 1 data: 01 text:

RECV: device: 1, command: device descriptor, data size: 28 data: 04 54 45 53 54 02 01 04 41 43 54 31 03 00 00 00 01 02 04 41 43 54 32 03 00 00 00 01 text: TESTACT1ACT2

[cc-lib] device descriptor received [cc-lib] id: 1, uri: TEST [cc-lib] label:  [cc-lib] channel: 1 [cc-lib] actuators count: 65 SEND: device: 1, command: device descriptor, data size: 1 data: 01 text:

But Button.ino, Pot.ino tests on cc-arduinolib only show initialization message and no other protocol message: $ controlchaind /dev/ttyUSB0 -f [cc-lib] control chain started (port: /dev/ttyUSB0, baud rate: 115200)

I modified an example using LCD and buttons where message is printed on LCD when a button is pressed, but ATMega seems blocked and nothing is printed when running cc-run. I have tried previous versions of cc-master and cc-slave with same results, though not all versions of cc-master were built successfully. Not sure how to debug this.

Rezzonics commented 3 years ago

After solving issue on handshake.c RANDOM_RANGE divide by zero issue I have output on Button.ino example, but isn't it supposed to send a message when button is pressed? I have an initial message at start and nothing when I press button:

$ controlchaind /dev/ttyUSB0 -f [cc-lib] control chain started (port: /dev/ttyUSB0, baud rate: 115200) RECV: device: 0, command: handshake, data size: 7 data: BE 1D 00 06 00 05 01 text:

[cc-lib] handshake received [cc-lib] random id: 7614 [cc-lib] protocol: v0.6 [cc-lib] firmware: v0.6.0 SEND: device: 0, command: handshake, data size: 4 data: BE 1D 00 01 text:

SEND: device: 1, command: device descriptor, data size: 1 data: 00 text:

RECV: device: 1, command: device descriptor, data size: 94 data: 48 68 74 74 70 73 3A 2F 2F 67 69 74 68 75 62 2E 63 6F 6D 2F 6D 6F 64 64 65 76 69 63 65 73 2F 63 63 2D 61 72 64 75 69 6E 6F 2D 6C 69 62 2F 74 72 65 65 2F 6D 61 73 74 65 72 2F 65 78 61 6D 70 6C 65 73 2F 42 75 74 74 6F 6E 06 42 75 74 74 6F 6E 01 07 50 72 65 73 73 4D 65 03 00 00 00 01 text: Hhttps://github.com/moddevices/cc-arduino-lib/tree/master/examples/ButtonButtonPressMe

[cc-lib] device descriptor received [cc-lib] id: 1, uri: https://github.com/moddevices/cc-arduino-lib/tree/master/examples/Button [cc-lib] label: Button [cc-lib] channel: 0 [cc-lib] actuators count: 1 SEND: device: 1, command: device descriptor, data size: 1 data: 01 text:

Rezzonics commented 3 years ago

When I run python3 cc_client.py I get more output, but nothing when I push button:

$ python3 cc_client.py devices list: [1] dev: 1, descriptor: {'label': 'Button', 'uri': 'https://github.com/moddevices/cc-arduino-lib/tree/master/examples/Button', 'version': '0.5.1', 'protocol': '0.5', 'actuators': [{'id': 0, 'name': 'PressMe', 'supported_modes': 3, 'max_assignments': 1}]} creating assignment assignment id: 0 device_status_cb: {'device_id': 1, 'status': 0} removing assignment done

And on cc-master I have assignment messages:

RECV: device: 0, command: handshake, data size: 7 data: D7 6C 00 06 00 05 01 text: l

[cc-lib] handshake received [cc-lib] random id: 27863 [cc-lib] protocol: v0.6 [cc-lib] firmware: v0.6.0 SEND: device: 0, command: handshake, data size: 4 data: D7 6C 00 01 text: l

chain_sync: request device descriptor SEND: device: 1, command: device descriptor, data size: 1 data: 00 text:

RECV: device: 1, command: device descriptor, data size: 94 data: 48 68 74 74 70 73 3A 2F 2F 67 69 74 68 75 62 2E 63 6F 6D 2F 6D 6F 64 64 65 76 69 63 65 73 2F 63 63 2D 61 72 64 75 69 6E 6F 2D 6C 69 62 2F 74 72 65 65 2F 6D 61 73 74 65 72 2F 65 78 61 6D 70 6C 65 73 2F 42 75 74 74 6F 6E 06 42 75 74 74 6F 6E 01 07 50 72 65 73 73 4D 65 03 00 00 00 01 text: Hhttps://github.com/moddevices/cc-arduino-lib/tree/master/examples/ButtonButtonPressMe

[cc-lib] device descriptor received [cc-lib] id: 1, uri: https://github.com/moddevices/cc-arduino-lib/tree/master/examples/Button [cc-lib] label: Button [cc-lib] channel: 0 [cc-lib] actuators count: 1 SEND: device: 1, command: device descriptor, data size: 1 data: 01 text:

[cc-lib] assignment received (id: 0) [cc-lib] requesting assignment to device (id: 0) SEND: device: 1, command: assignment, data size: 56 data: 00 00 04 47 61 69 6E 00 00 80 3F 00 00 00 00 00 00 20 41 00 00 80 40 04 00 00 00 20 00 02 64 42 03 02 70 69 DC 0F 49 40 01 65 4D F8 2D 40 05 64 6F 7A 65 6E 00 00 40 41 text: Gain? A@ dBpiI@eM-@dozen@A

RECV: device: 1, command: assignment, data size: 0 data: text:

[cc-lib] assignment received [cc-lib] id: 1, uri: https://github.com/moddevices/cc-arduino-lib/tree/master/examples/Button [cc-lib] label: Button [cc-lib] channel: 0 [cc-lib] actuators count: 1 [cc-lib] assignment done (id: 0) [cc-lib] device timeout (device id: 1) [cc-lib] unassignment received (id: 0, ret: -1)

progtologist commented 3 years ago

The cc_client.py has hardcoded assignment values for the identified hardware which might not work for your mod-cc client. Try changing them to match with your arduino code and it should eventually work. Otherwise, plugging it in a MODDUO device will recognise the capabilities and show them in the effect assignment options. If you don't have a MODDUO device, how do you plan on testing this?

Rezzonics commented 3 years ago

Thanks for the answer. I am aiming for a MOD DWARF, but at the moment I am using a Linux PC (with cc_control.py) and a SBC (similar to Raspberry Pi)

I guess that I have to modify line 142 on cc_client.py assignment = {'device_id':1, 'actuator_id':0, 'label':'Gain', 'value':1.0, 'min':0.0, 'max':10.0, 'def':4.0, 'mode':0x04, 'steps':32, 'unit':'dB', 'options': [{'pi': 3.141593}, {'e': 2.71828}, {'dozen': 12.0}]} https://github.com/moddevices/cc-master/blob/master/client/src/cc_client.py not sure what to use on def, mode, steps, unit and options though. I will try different values and see how it goes.

I think there is an issue with Arduino TimeOne library, there is an immediate interrupt when calling Timer1.start on timer_set function (timer.cpp line 82). Setting TCNT1= 0 triggers and interrupt. Line 85 on TimerOne.h TCNT1 = 0; // TODO: does this cause an undesired interrupt? https://github.com/PaulStoffregen/TimerOne/blob/1.1/TimerOne.h The comment on Timer1.start actually states that there might be an undesired interrupt. I think that I can confirm it. I discovered the issue by making a simple example using an LED and a button and using a long 4s timer period. When I push the button, LED turns off and immediately on, when actually it should wait 4s to turn on. To deal with it on the example and cc-arduino-lib, I have added a flag on timer1_callback() function, that toggles its value between 0 and 1, so that when flag is 0 it just sets it to 1 and returns. This is not very elegant but on the 4s timer example it worked. It would probably be better to use a different timer library though.

progtologist commented 3 years ago

I haven't had any issues with the TimerOne library, but I am using a Teensy board (over USB Serial) myself so it might be related why my fork works. I also had similar issues to yours, but I managed to fix them by modifying the cc_client.py - I changed actuator_id to match my button example and mode to be 0x02 if I remember correctly.

I did all these because I was using MODEP, and when I plugged the device into it, no assignment happened because the cc_master was not installed and mod-ui had CC functionality commented out by their maintainers. I have since fixed those issues with MODEP manually and now it works without major problems.

Feel free to checkout my fork of cc_arduino_lib to see what modifications I applied to make it work for teensy 4.1

I also checked PedalpII, it is very interesting but the RPi images don't work out of the box and building it from source (to attempt to fix the problems) requires way too much storage space for my liking :(