I have recently purchased a Beaglebone Black and the CAN CAPE, COMCPE-BBBCAPE
I need to receive CAN messages, combine the content of the data, and send it out the Ethernet port of the Beaglebone using UDP.
I’m looking for example code for the CAN CAPE. I struggling to find details on how to use the CAN CAPE that I purchased.
I’d like to use Python or Javascript, but would accept most any language.
Well the can pins are using P9.24/P9.26
First double check that they loaded:
sudo /opt/scripts/tools/version.sh
Then take a look at these two sites on can:
Regards,
Hi Robert,
Thank you for this information.
I have looked at the GitHub link you provided and see two different source files, candump.c and cansniffer.c that I believe would get me on the right path.
Can you tell me what I need to do to my Beaglebone Black with the CAN Cape to get the code candump.c to actually run?
Thanks,
Dave
You can build that project by following this:
sudo apt update
sudo apt install build-essential cmake git ninja-build
git clone https://github.com/linux-can/can-utils
cd ./can-utils/
mkdir build
cd ./build/
cmake -GNinja .. && ninja
debian@beaglebone:~/can-utils/build$ cmake -GNinja .. && ninja
-- The C compiler identification is GNU 6.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/debian/can-utils/build
[48/63] Building C object CMakeFiles/c...bit-timing.dir/can-calc-bit-timing.c.o
/home/debian/can-utils/can-calc-bit-timing.c: In function ‘print_bit_timing’:
/home/debian/can-utils/can-calc-bit-timing.c:447:35: warning: ‘tseg1’ may be used uninitialized in this function [-Wmaybe-uninitialized]
unsigned int brp, tsegall, tseg, tseg1, tseg2;
^~~~~
/home/debian/can-utils/can-calc-bit-timing.c:447:42: warning: ‘tseg2’ may be used uninitialized in this function [-Wmaybe-uninitialized]
unsigned int brp, tsegall, tseg, tseg1, tseg2;
^~~~~
[63/63] Linking C executable isotpsniffer
debian@beaglebone:~/can-utils/build$ ls
asc2log canlogserver isotprecv libcan.a
bcmserver canplayer isotpsend libj1939.a
build.ninja cansend isotpserver log2asc
canbusload cansniffer isotpsniffer log2long
can-calc-bit-timing CMakeCache.txt isotptun rules.ninja
candump CMakeFiles jacd slcan_attach
canfdtest cmake_install.cmake jcat slcand
cangen isotpdump jspy slcanpty
cangw isotpperf jsr testj1939
Regards,
Hi Robert,
With your last email I was able to modify the candump program to do exactly what I need done.
Every CAN message received is reformatted and sent as an Ethernet UDP message.
I need help with one more thing.
I have the Beaglebone initializing the CAN interface and am at the point where I simply have to run the executable program after it boots up, but I can’t get it to run automatically.
Could you describe how you would get the candump program to run automatically?
Thanks,
Dave
RobertCNelson
Applications Engineer
February 19
dpengsberg:
Can you tell me what I need to do to my Beaglebone Black with the CAN Cape to get the code candump.c to actually run?
sudo apt update
sudo apt install build-essential cmake git ninja-build
git clone https://github.com/linux-can/can-utils
cd ./can-utils/
mkdir build
cd ./build/
cmake -GNinja .. && ninja
ebian@beaglebone:~/can-utils$ cd build/
debian@beaglebone:~/can-utils/build$ cmake -GNinja .. && ninja
-- The C compiler identification is GNU 6.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/debian/can-utils/build
[48/63] Building C object CMakeFiles/c...bit-timing.dir/can-calc-bit-timing.c.o
/home/debian/can-utils/can-calc-bit-timing.c: In function ‘print_bit_timing’:
/home/debian/can-utils/can-calc-bit-timing.c:447:35: warning: ‘tseg1’ may be used uninitialized in this function [-Wmaybe-uninitialized]
unsigned int brp, tsegall, tseg, tseg1, tseg2;
^~~~~
/home/debian/can-utils/can-calc-bit-timing.c:447:42: warning: ‘tseg2’ may be used uninitialized in this function [-Wmaybe-uninitialized]
unsigned int brp, tsegall, tseg, tseg1, tseg2;
^~~~~
[63/63] Linking C executable isotpsniffer
debian@beaglebone:~/can-utils/build$ ls
asc2log canlogserver isotprecv libcan.a
bcmserver canplayer isotpsend libj1939.a
build.ninja cansend isotpserver log2asc
canbusload cansniffer isotpsniffer log2long
can-calc-bit-timing CMakeCache.txt isotptun rules.ninja
candump CMakeFiles jacd slcan_attach
canfdtest cmake_install.cmake jcat slcand
cangen isotpdump jspy slcanpty
cangw isotpperf jsr testj1939
Regards,
I would setup a systemd service file to launch your application.
See for example: Use systemd to Start a Linux Service at Boot | Linode Docs
Regards,
Hi Robert,
I’m having some trouble and some success in automatically booting up. But I think I can figure it out.
Do you handle or know of a small housing tall enough to hold the BBB and the CAN Cape? I have two from digi-key that are not quite tall enough.
Thank you,
Dave
RobertCNelson
Applications Engineer
March 4
dpengsberg:
Could you describe how you would get the candump program to run automatically?
I would setup a systemd service file to launch your application.
See for example: https://www.linode.com/docs/quick-answers/linux/start-service-at-boot/
Regards,
Hi again - I wonder if you could point me to a way to get a browser to display a static website on powerup. I have installed chromium.
Somehow I thought by running chromium from a putty command line it would show up on the hdmi, but that doesn’t work or really make sense. How can I get hdmi output without logging through some sort of hdmi console?
Thanks for all your help.
Dave
Hi Robert,
I’m having some trouble and some success in automatically booting up. But I think I can figure it out.
Do you handle or know of a small housing tall enough to hold the BBB and the CAN Cape? I have two from digi-key that are not quite tall enough.
Thank you,
Dave
RobertCNelson
Applications Engineer
March 4
dpengsberg:
Could you describe how you would get the candump program to run automatically?
I would setup a systemd service file to launch your application.
See for example: https://www.linode.com/docs/quick-answers/linux/start-service-at-boot/
Regards,
This will depend on the what Windows Manager you are using. Lxqt/gnome/qt/openbox/etc…
My usual go to is “slim/openbox”…
1: slim log’s the user in, and runs openbox.
2: openbox, runs the script: {home}/.config/openbox/autostart
Sadly, the answer is complex as it depends on a bunch of variables, even thou it seems like a simple question.
Regards,
Most of the default BBB housing, where never designed for cape usage.
A few of our box suppliers offer customization’s based off a current box form. What dimensions are you looking for in a housing?
Regards,
That is too bad they don’t have them tall enough to accept a cape.
I will have to figure out the height I need and get back to you.
Thanks for all your help.
On the hdmi topic, I will see if I can figure out the slim/openbox you mention.
Dave
RobertCNelson
Applications Engineer
March 5
dpengsberg:
Do you handle or know of a small housing tall enough to hold the BBB and the CAN Cape? I have two from digi-key that are not quite tall enough.
Most of the default BBB housing, where never designed for cape usage.
A few of our box suppliers offer customization’s based off a current box form. What dimensions are you looking for in a housing?
Regards,
Hi Dave,
Here is one example: (you’ll have to read between the lines, as it’s mixing a qt application into my autostart)
Regards,
Would something like:
work?
Hi Robert,
I have installed slim:
sudo apt update
sudo apt install slim
On reboot I expected a login screen to appear on the monitor connected to my hdmi port, but I just get a login prompt.
I edited the /etc/slim.conf file to auto login - yes , and rebooted, but still no login screen or auto login.
I am missing something.
I did not install openbox yet. Do I need that first?
Thanks,
Dave
RobertCNelson
Applications Engineer
March 5
dpengsberg:
Hi again - I wonder if you could point me to a way to get a browser to display a static website on powerup. I have installed chromium.
Somehow I thought by running chromium from a putty command line it would show up on the hdmi, but that doesn’t work or really make sense. How can I get hdmi output without logging through some sort of hdmi console?
This will depend on the what Windows Manager you are using. Lxqt/gnome/qt/openbox/etc…
My usual go to is “slim/openbox”…
1: slim log’s the user in, and runs openbox.
2: openbox, runs the script: {home}/.config/openbox/autostart
Sadly, the answer is complex as it depends on a bunch of variables, even thou it seems like a simple question.
Regards,
Hi Robert,
I have made considerable progress now having an autologin (lightdm) and ability to autostart an application (openbox).
I hope you will help me with understanding something. Chromium browser is crashing. It is version 70 and seems that others have had success downgrading to version 67. I have been experimenting with both the IoT image and the LXQT image, and notice LXQT is using version 67 without crashing. When I install chromium in the IoT image I get version 70.
Can you please tell me how to install downgraded chromium? Do I first install current version and then install the lower version on top? Do I simply install the 67 version on a fresh image? LXQT image uses 67.0.3396.87 - can’t seem to find instructions on how to install a downgraded version.
Thank you very much,
David
RobertCNelson
Applications Engineer
March 5
dpengsberg:
On the hdmi topic, I will see if I can figure out the slim/openbox you mention.
Hi Dave,
Here is one example: (you’ll have to read between the lines, as it’s mixing a qt application into my autostart)
Regards,
So yes, version 70 and 72 in Debian Stretch are currently “busted” for armhf hardware. (not just the Beagle’s…)
So first, remove your current version of chromium:
sudo apt update
sudo apt remove chromium --purge
Next, using apt-cache, to list every specific version of chromium available.
sudo apt update
sudo apt-cache madison chromium
chromium | 72.0.3626.122-1~deb9u1 | http://deb.debian.org/debian-security stretch/updates/main armhf Packages
chromium | 70.0.3538.110-1~deb9u1 | http://deb.debian.org/debian stretch/main armhf Packages
chromium | 67.0.3396.87-1~deb9u1rcnee0~stretch+20180925 | http://repos.rcn-ee.com/debian stretch/main armhf Packages
Now Install the old version via:
sudo apt -y --allow-downgrades install chromium=67.0.3396.87-1~deb9u1rcnee*
Next, lock the package so apt update/apt upgrade will not automatically upgrade it:
sudo apt-mark hold chromium
Regards,
PS, i did recently try to build 71.0.3578.80-1, but that failed with:
ERROR at //skia/BUILD.gn:54:3: Replacing nonempty list.
defines = skia_for_chromium_defines
^------
This overwrites a previously-defined nonempty list with another nonempty list.
See //third_party/skia/third_party/skcms/skcms.gni:7:15: for previous definition
defines = [ "SKCMS_PORTABLE=1" ]
^--------------------
Did you mean to append/modify instead? If you really want to overwrite, do:
foo = []
before reassigning.
See //BUILD.gn:69:5: which caused the file to be included.
"//skia:skia_unittests",
^----------------------
debian/rules:96: recipe for target 'override_dh_auto_configure' failed
make[1]: *** [override_dh_auto_configure] Error 1
make[1]: Leaving directory '/<<PKGBUILDDIR>>'
I should check if 72.0.3626.122-1 will build/work on armhf… (it only takes 2-3 days to actually build the package…)
Regards,
Hi Robert,
That worked my project is very close to done. Chromium is complaining, but runs.
debian@beaglebone:~$ chromium
[4103:4194:0315/044831.292466:ERROR:object_proxy.cc(617)]
Failed to call method: org.freedesktop.Notifications.GetCapabilities: object_path= /org/freedesktop/Notifications:
org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files
Can’t read /proc/cpuinfo: Operation not permitted
Can’t read /proc/cpuinfo: Operation not permitted
[4103:4103:0315/044852.626628:ERROR:latency_info.cc(164)]
Surface::TakeLatencyInfoFromFrame, LatencyInfo vector size 101 is too big.
Can’t read /proc/cpuinfo: Operation not permitted
Can’t read /proc/cpuinfo: Operation not permitted
I have modified the candump.c project to send the received can msg out the ethernet port as UDP. This is working but I would very much like to blink an external LED from a GPIO pin. After reviewing the samples and putting some test code in the candump.c file, I always get a “segmentation error” when the code executes the fwrite instruction.
MAYBE there is a simpler way. I tried an fprintf, but also get the segmentation error. This approach seems very complicated for turning digital outputs on and off.
FILE *export_file = NULL;
FILE *IO_direction = NULL;
char *strlow = “low”;
char *strhigh = “high”;
char strgpio = “23”; // GPIO0_23 means 032 + 23 = 23. Hence pass this value to the ‘export’ file.
export_file = fopen (“/sys/class/gpio/export”, “w”);
fwrite (strgpio, 1, sizeof(strgpio), export_file);
fclose (export_file);
for (int i=0;i< 100; i++) {
IO_direction = fopen (“/sys/class/gpio/gpio23/direction”, “w”);
fwrite (strhigh, 1, sizeof(strhigh), IO_direction); //set the pin to HIGH
fclose (IO_direction);
usleep (1000000);
IO_direction = fopen (“/sys/class/gpio/gpio23/direction”, “w”);
fwrite (strlow, 1, sizeof(strlow), IO_direction); //set the pin to LOW
fclose (IO_direction);
usleep (1000000);
}
export_file = fopen (“/sys/class/gpio/unexport”, “w”); //remove the mapping
fwrite (strgpio, 1, sizeof(strgpio), export_file);
fclose (export_file);
RobertCNelson
Applications Engineer
March 14
dpengsberg:
Can you please tell me how to install downgraded chromium? Do I first install current version and then install the lower version on top? Do I simply install the 67 version on a fresh image? LXQT image uses 67.0.3396.87 - can’t seem to find instructions on how to install a downgraded version.
So yes, version 70 and 72 in Debian Stretch are currently “busted” for armhf hardware. (not just the Beagle’s…)
So first, remove your current version of chromium:
sudo apt update
sudo apt remove chromium --purge
Next, using apt-cache, to list every specific version of chromium available.
sudo apt update
sudo apt-cache madison chromium
chromium | 72.0.3626.122-1~deb9u1 | http://deb.debian.org/debian-security stretch/updates/main armhf Packages
chromium | 70.0.3538.110-1~deb9u1 | http://deb.debian.org/debian stretch/main armhf Packages
chromium | 67.0.3396.87-1~deb9u1rcnee0~stretch+20180925 | http://repos.rcn-ee.com/debian stretch/main armhf Packages
Now Install the old version via:
sudo apt -y --allow-downgrades install chromium=67.0.3396.87-1~deb9u1rcnee*
Next, lock the package so apt update/apt upgrade will not automatically upgrade it:
sudo apt-mark hold chromium
Regards,
Just add an gpio-leds device tree node… Look at this 4 relay “led” example:
Then you can toggle it like so:
echo 1 > /sys/class/leds/*name*/brightness
echo 0 > /sys/class/leds/*name*/brightness
echo 1 > /sys/class/leds/*name*/brightness
Regards,
Thank you very much Robert.
I have another requirement, which is to measure 3 incoming pwm signals, modify the pulse width based on a value being received from the CAN bus, then output the 3 modified pwm signals.
The incoming pwm is 20 milliseconds over all (50 hz) with the pulse width varying between 1.0 to 2.0 milliseconds. The output is the same specs, although the pulse width will be slightly different than the incoming based on an offset from the CAN value.
Do you think the BeagleBone Black has the capability and speed to do this?
Can I accurately measure the incoming pwm, as well as accurately output one?
Again, C would be the language.
Thanks,
Dave