Great, thanks, will give this a try.
Bela & arduino
Hello, finally had time to come back to this, but can't seem to get it to work.
So far I've:
- Loaded the UART4 device tree overlay
- Set up a simple sketch on an Arduino Uno which writes a single number to serial
- Wired up the Arduino to send this data from D1 to Bela P09_11, via a logic level converter (https://www.sparkfun.com/products/12009), sharing common ground.
- Set up a simple _main.pd patch which should receive the serial data through the [comport] object and print it to the console.
But so far, nothing. I know in this thread (https://forum.bela.io/d/620-bela-mini-midi-input-on-uart0) you mentioned not to use [comport] but said it may work if it uses pd's own functions. Thought I'd give it a try but not sure at what point it's failing.
I've looked at the other threads (eg. https://forum.bela.io/d/104-usb-serial-port-input-into-bela/11) and I can't really follow how to pick up serial in C++ first then send it to PD. Is there a simpler way to get serial data into PD?
can you try to receive the bytes from the terminal using screen
?
That would be
screen /dev/ttyS4 115200
assuming 115200 is the speed of the port.
emerson But so far, nothing. I know in this thread (https://forum.bela.io/d/620-bela-mini-midi-input-on-uart0) you mentioned not to use [comport] but said it may work if it uses pd's own functions
Did you compile [comport]
for yourself ? Does it show an error message in the console like "couldn't find [comport]
" ?
Yes it says "error - couldn't create". I hadn't compiled it so now following this thread (https://forum.bela.io/d/101-compiling-puredata-externals/56) - but stuck again so will post there.
Hello, i want to setup i2c-communication (with bela as master and arduino uno as slave.) i followed this tutorial for doing this with raspberry pi + arduino : https://www.youtube.com/watch?v=me7mhrRbspk&t=1203s
and succesfully controlled the arduino led from the bela using a python script. now i want to send some bytes to the arduino from a pd patch running on my bela. how can i tell pd to send something to a slave adress?
How good is your C++? Looking at the Trill library should be a good starting point for your application. What sort of messages are you trying to send? Are you also receiving messages?
- Edited
My C++ is not that fantastic. I do want to receive messages back. right now i'm just trying to send some ints to the arduino and print them in the serial port (and send them back to pd); in the end i want to read out some sensor values and receive them on the bela. I tried loading the default_libpd_render.cpp, I2cRt.h and I2cRt.cpp from the better-i2c branch into my project, but i get the next error: variable type 'I2cRt' is an abstract class column: 7, line: 36
/root/Bela/projects/Swept_Cap_Sensor_Project/render.cpp:36:7: error: variable type 'I2cRt' is an abstract class
I2cRt i2c;
^
./include/I2c.h:33:14: note: unimplemented pure virtual method 'readI2C' in 'I2cRt'
virtual int readI2C() = 0;
^
1 error generated.
make: *** [/root/Bela/projects/Swept_Cap_Sensor_Project/build/render.o] Error 1
the better-i2c
branch has a lot of good things that were almost working at the time, but won't necessarily easily work now. I tried to do a quick git rebase
, but it's not so straightforward. As for the specific error you are getting you should also load the include/I2c.h
file from the same branch.
giuliomoro giuliomoro thanks, i got it working with the test values i only get 1 warning at build:
In file render.cpp: [warning] unused variable 'pd_that' [-Wunused-variable] column: 22, line: 407
; but I noticed that in the latest default libpd render.cpp file (from the master branch) that te line t_pdinstance* pd_that = (t_pdinstance*)arg;
, which is generating this warning is completely gone. I think it is from an old libpd version, but I'm not sure what it does. My test values are coming through, so I think i can just ignore the warning/ delete this line. (?)
Yes you can delete it.. So are you using the code from the other branch in the end?
giuliomoro yes i am using all code from the better-I2c branch; (libpd_default_render.cpp , i2C.cpp , i2c.h , i2cRt.ccp i2cRt.h , ringbuffer.c and ringbuffer.h) I just merged it with another project, and it's working fine.
giuliomoro now everything works, I want to compile this project with hvcc; it compiled succesfully, but i don't receive messages from the slave device anymore, also it doesn't send the messages to the slave device. I am using the render.cpp from/better-i2c/scripts/hvresources/render.cpp
. in the 'libpd version' i am sending a couple of messages from my pd patch to the receiver "bela_i2c"
, and am receiving messages in pd with a receive object "bela_i2c_in"
. they are defined in the default_libpd_render.cpp
from the better-i2c branch. (but i can't find any reference to these in the heavy version of the render.cpp
).. only thing i found is : // unlike libpd, no need here to bind the bela_digitalOut.. receivers
I figured i probably have to do something with this, but C++ is new to me. i'm able to understand code, and alter it a bit to do what i want, but if i'm writing /adding new code myself I don't know excactly what I am doing. Could you help me put this in the heavy version of the render.cpp?
// but make sure you do something like [send receiverName @hv_param]
// when you want to send a message from Heavy to the wrapper.
getting there ... I rebased that branch on top of the current dev
(here), and everything seems to be working ok, although it surely could be optimized a bit. Next step: heavy!
here is the updated Heavy render file: https://github.com/BelaPlatform/Bela/blob/better-i2c-rebased/scripts/hvresources/render.cpp
Note that you now have to send to [send bela_i2c @hv_param]
, as per the updated example: https://github.com/BelaPlatform/Bela/blob/better-i2c-rebased/examples/PureData/i2c/_main.pd
giuliomoro thanks a bunch! i will let you know when i tested it!
- Edited
giuliomoro the compiler seems to have trouble with finding the "I2cRt.h" file . echo 'Building render.cpp...'
Building render.cpp...
g++ -I/root/Bela/projects/CapSens_HEAVY_2 -I./include/legacy -I./include -I./build/pru/ -I./ -I/usr/xenomai/include/cobalt -I/usr/xenomai/include -march=armv7-a -mfpu=vfp3 -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__COBALT__ -D__COBALT_WRAP__ -DXENOMAI_SKIN_posix -DXENOMAI_MAJOR=3 -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize -ffast-math -DNDEBUG -DBELA_USE_RTDM -I/root/Bela/resources/stretch/include -save-temps=obj -std=c++11 -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"/root/Bela/projects/CapSens_HEAVY_2/build/render.d" -o "/root/Bela/projects/CapSens_HEAVY_2/build/render.o" "/root/Bela/projects/CapSens_HEAVY_2/render.cpp"
/root/Bela/projects/CapSens_HEAVY_2/render.cpp:45:19: fatal error: I2cRt.h: No such file or directory
#include <I2cRt.h>
^
compilation terminated.
Makefile:459: recipe for target '/root/Bela/projects/CapSens_HEAVY/build/render.o' failed
make: *** [/root/Bela/projects/CapSens_HEAVY/build/render.o] Error 1
make: Leaving directory '/root/Bela'
I tried compiling two different projects: one with files from the old better-i2c branch; (the libpd version builds and works fine) and the other one is the same project but with all files updated to those of the rebased better-i2c branch. they gave me excactly the same results.
also, you might want to know: when i updated the default_libpd_render.cpp
file to the rebased one, it gave me some errors:
no matching member function for call to 'sendBuffer' column: 8, line: 202
and
no matching member function for call to 'sendBuffer' column: 10, line: 214
./libraries/Gui/Gui.h:128:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
. because it said: requires 2 arguments but 3 were provided, i removed the second argument in the corresponding functions: removed
int Gui::sendBuffer(unsigned int bufferId, std::vector<T,A> & buffer)
^
./libraries/Gui/Gui.h:135:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
int Gui::sendBuffer(unsigned int bufferId, T (&buffer)[N])
^
./libraries/Gui/Gui.h:142:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
int Gui::sendBuffer(unsigned int bufferId, T value)
^
/root/Bela/projects/I2c_Rebase/render.cpp:214:10: error: no matching member function for call to 'sendBuffer'
gui.sendBuffer(bufNum, s, strlen(s));
~~~~^~~~~~~~~~
./libraries/Gui/Gui.h:128:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
int Gui::sendBuffer(unsigned int bufferId, std::vector<T,A> & buffer)
^
./libraries/Gui/Gui.h:135:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
int Gui::sendBuffer(unsigned int bufferId, T (&buffer)[N])
^
./libraries/Gui/Gui.h:142:10: note: candidate function template not viable: requires 2 arguments, but 3 were provided
int Gui::sendBuffer(unsigned int bufferId, T value)"buf"
in gui.sendBuffer(bufNum, buf, argc - 1);
(line 202) and "s"
in gui.sendBuffer(bufNum, s, strlen(s));
(line 214) Again, i do not know excactly what this is doing; but only after removing these arguments the project built and the libpd version worked with no problems.
It seems like you are just copying files in from one branch to another. That is a recipe for disaster, as you find yourself in a situation where a file (e.g.: core/default_libpd_render.cpp
) relies on the version of libraries/Gui/Gui.h
that is available on both the dev
and better-i2c-rebased
branches. Similarly, the render.cpp
file for heavy that you are using relies on I2cRt.h
to be present in the include/
folder, as it is in the better-i2c-rebased
branch. To try out a branch properly, you have to update all the codebase at the same time. This procedure is explained here.
giuliomoro Thanks, that did the job! i feel a bit stupid for not reading that myself to begin with the project now compiled to heavy succesfully; only one problem left; I think the Trill library isn't working correctly on this branch : the other project that i wanted to merge it with now doesn't want to build anymore, I get the error:
In file libraries/Trill/Trill.cpp: use of undeclared identifier 'i2C_file'; did you mean 'i2cFile'? column: 33, line: 92 libraries/Trill/Trill.cpp:92:33: error: use of undeclared identifier 'i2C_file'; did you mean 'i2cFile'?
if(int writtenValue = (::write(i2C_file, buf, bytesToWrite)) != bytesToWrite)
^~~~~~~~
i2cFile
/root/Bela/include/I2c.h:27:6: note: 'i2cFile' declared here
int i2cFile = 0;
and 12 more errors similar to this on other lines. they all refer to "i2c_file".
(i tried altering the Trill.cpp file in my downloaded "better-i2c-rebased" folder on my pc accordingly, rezip it and update the board with the altered branch, but that didn't work, it even showed the exact same errors. probably not at all the way to do this but at least i wanted to give that a try before i did another post)
Yes it was broken. I fixed it now.
Thanks! the libpd project is building again with no errors. With heavy there still seem to be some issues: it doesnt want to accept the expression object from pd anymore; (in the master branch that compiled with no problems); root@bela:~# python2.7 ~/hvcc/hvcc.py ~/Bela/projects/MergedProjects/_main.pd -o /tmp/hvtmp -n bela -g c
also when i try to compile the project with the expression object removed, the compiler still quits with 'segmentation fault': (everything seems to run smooth untill compiling the render.cpp)
1) Error pd2hv: BaseMath in "_main.pd/BaseMath" @ (x:-515, y:498): Don't know how to parse object "expr". Is it an object supported by Heavy? Is it an abstrac tion? Have the search paths been correctly configured?
2) Error pd2hv: BaseMath in "_main.pd/BaseMath" @ (x:-515, y:498): There was a n error while connecting two objects. Have all objects been correctly instantiat ed? Have all inlets and outlets been declared?
3) Error pd2hv: [comment text] in "_main.pd/BaseMath" @ (x:0, y:0): Connection made to non-existent inlet at [comment {u'text': 'null object placeholder (expr )'}]:0.echo 'Building render.cpp...'
Building render.cpp...
g++ -I/root/Bela/projects/Trill_HEAVY -I./include/legacy -I./include -I./build /pru/ -I./ -I/usr/xenomai/include/cobalt -I/usr/xenomai/include -march=armv7-a - mfpu=vfp3 -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__COBALT__ - D__COBALT_WRAP__ -DXENOMAI_SKIN_posix -DXENOMAI_MAJOR=3 -O3 -march=armv7-a -mtun e=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize -ffast-math -DNDEBUG -D BELA_USE_RTDM -I/root/Bela/resources/stretch/include -save-temps=obj -std=c++11 -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"/root/Bela/projects/T rill_HEAVY/build/render.d" -o "/root/Bela/projects/Trill_HEAVY/build/render.o" " /root/Bela/projects/Trill_HEAVY/render.cpp"
/root/Bela/projects/Trill_HEAVY/render.cpp: In function 'void sendHook(HeavyCont extInterface*, const char*, uint32_t, const HvMessage*)':
/root/Bela/projects/Trill_HEAVY/render.cpp:410:9: warning: comparison between si gned and unsigned integer expressions [-Wsign-compare]
port < midi.size() && midi[port]->writeNoteOn(channel, pitch, velocity);
~~~~~^~~~~~~~~~~~~
/root/Bela/projects/Trill_HEAVY/render.cpp:420:9: warning: comparison between si gned and unsigned integer expressions [-Wsign-compare]
port < midi.size() && midi[port]->writeControlChange(channel, controller, va lue);
~~~~~^~~~~~~~~~~~~
/root/Bela/projects/Trill_HEAVY/render.cpp:428:9: warning: comparison between si gned and unsigned integer expressions [-Wsign-compare]
port < midi.size() && midi[port]->writeProgramChange(channel, program);
~~~~~^~~~~~~~~~~~~
/root/Bela/projects/Trill_HEAVY/render.cpp:437:9: warning: comparison between si gned and unsigned integer expressions [-Wsign-compare]
port < midi.size() && midi[port]->writePitchBend(channel, value);
~~~~~^~~~~~~~~~~~~
/root/Bela/projects/Trill_HEAVY/render.cpp:446:9: warning: comparison between si gned and unsigned integer expressions [-Wsign-compare]
port < midi.size() && midi[port]->writeChannelPressure(channel, pressure);
~~~~~^~~~~~~~~~~~~
/root/Bela/projects/Trill_HEAVY/render.cpp:456:9: warning: comparison between si gned and unsigned integer expressions [-Wsign-compare]
port < midi.size() && midi[port]->writePolyphonicKeyPressure(channel, pitch, pressure);
~~~~~^~~~~~~~~~~~~
/root/Bela/projects/Trill_HEAVY/render.cpp:464:9: warning: comparison between si gned and unsigned integer expressions [-Wsign-compare]
port < midi.size() && midi[port]->writeOutput(byte);
~~~~~^~~~~~~~~~~~~
/root/Bela/projects/Trill_HEAVY/render.cpp: In function 'bool setup(BelaContext* , void*)':
/root/Bela/projects/Trill_HEAVY/render.cpp:487:28: warning: comparison between s igned and unsigned integer expressions [-Wsign-compare]
for(unsigned int n = 0; n < touchSensor.numSensors(); ++n)
~~^~~~~~~~~~~~~~~~~~~~~~~~~~
``echo ' ...done'
...done
echo ' '
./resources/tools/detectlibraries.sh --project Trill_HEAVY
Extracting dependencies of library Midi
Extracting dependencies of library Scope
Extracting dependencies of library Trill
make -f Makefile.linkbela --no-print-directory /root/Bela/projects/Trill_HEAVY/T rill_HEAVY
echo 'Linking...'
Linking...
g++ -Llib/ -fno-pie -no-pie -pthread -o "/root/Bela/projects/Trill_HEAVY/Tri ll_HEAVY" build/core/FormatConvert.o build/core/OscillatorBank_routines.o build/ core/math_runfast.o build/core/ringbuffer.o build/core/Gpio.o build/core/I2c_Cod ec.o build/core/BelaContextFifo.o build/core/RTAudio.o build/core/PruBinary.o bu ild/core/RTAudioCommandLine.o build/core/AuxTaskNonRT.o build/core/JSONValue.o b uild/core/board_detect.o build/core/WSServer.o build/core/AuxiliaryTasks.o build /core/PRU.o build/core/DataFifo.o build/core/AuxTaskRT.o build/core/IirFilter.o build/core/GPIOcontrol.o build/core/Spi_Codec.o build/core/I2cRt.o build/core/I2 c.o build/core/BelaContextSplitter.o build/core/DigitalChannelManager.o build/co re/JSON.o ./build/core/default_main.o /root/Bela/projects/Trill_HEAVY/build/Hv ControlSlice.o /root/Bela/projects/Trill_HEAVY/build/HvControlVar.o /root/Bela/p rojects/Trill_HEAVY/build/HvLightPipe.o /root/Bela/projects/Trill_HEAVY/build/Hv Table.o /root/Bela/projects/Trill_HEAVY/build/HvMessageQueue.o /root/Bela/projec ts/Trill_HEAVY/build/HvControlPack.o /root/Bela/projects/Trill_HEAVY/build/HvCon trolCast.o /root/Bela/projects/Trill_HEAVY/build/HvControlSystem.o /root/Bela/pr ojects/Trill_HEAVY/build/HvMessage.o /root/Bela/projects/Trill_HEAVY/build/HvUti ls.o /root/Bela/projects/Trill_HEAVY/build/HvControlBinop.o /root/Bela/projects/ Trill_HEAVY/build/HvControlDelay.o /root/Bela/projects/Trill_HEAVY/build/HvContr olPrint.o /root/Bela/projects/Trill_HEAVY/build/HvMessagePool.o /root/Bela/proje cts/Trill_HEAVY/build/HvHeavy.o /root/Bela/projects/Trill_HEAVY/build/HeavyConte xt.o /root/Bela/projects/Trill_HEAVY/build/Heavy_bela.o /root/Bela/projects/Tril l_HEAVY/build/render.o libraries/Midi/build/Midi.o libraries/Midi/build/Midi_c.o libraries/Scope/build/Scope.o libraries/Trill/build/Trill.o -lasound -lseasoc ks -lNE10 -Wl,--no-as-needed -L/usr/xenomai/lib -lcobalt -lmodechk -lpthread -l rt -lprussdrv -lstdc++ -Wl,--no-as-needed -L/usr/xenomai/lib -lcobalt -lmodechk -lpthread -lrt -lasound -lseasocks -lNE10 -lmathneon -lmathneon
echo ' ...done'
...done
echo "Running /root/Bela/projects/Trill_HEAVY/Trill_HEAVY "
Running /root/Bela/projects/Trill_HEAVY/Trill_HEAVY
sync& cd /root/Bela/projects/Trill_HEAVY && /root/Bela/projects/Trill_HEAVY/Tril l_HEAVY
Segmentation fault
Makefile:564: recipe for target 'runonly' failed
make: *** [runonly] Error 139
make: Leaving directory '/root/Bela'