question

pierresmits avatar image
pierresmits asked

PiCAN-M + pi 3b+ + VenusOS

I recently purchased the Pican-M hat for the raspberry to have

a) the Pi powered through the nmea2000 bus/network, and

b) to have the data that comes through from the nmea2000 bus/network (and nmea0183) available in SignalK.

I tested this with a non-VenusOS setup (version 2.91), following the instructions found in https://seabits.com/set-up-signal-k-and-grafana-on-raspberry-pi-with-pican-m-nmea-2000-board/ and that worked as expected.

Trying to accomplish the same with VenusOs setup I got stuck on setting up the nmea2000/canbus setup.

Comparing both the instructions in the link above and those related to kwindrem/VeCanSetup and https://github.com/victronenergy/venus/wiki/RaspberryPi-CAN-Interfaces regarding the PiCan hat(s), I came to following in my /u-boot/config.text. However, It doesn't get me any date from the hat.

What am I doing wrong? How can I get this fixed? Any ideas?

Thanks - in advance - and best regards,

Pierre

[all]
enable_uart=1
dtparam=i2c_arm=on
dtparam=spi=on

# Bring up the PiCAN controllers.
dtoverlay=mcp2515-can0-overlay,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay
Venus OSRaspberry Pi
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

8 Answers
pierresmits avatar image
pierresmits answered ·

Additional info: ifconfig -a doesn't show the can0 interface. And can dump -x can0 gives a 'No such device

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

bathnm avatar image
bathnm answered ·

What are your system logs showing, aka dmesg

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Kevin Windrem avatar image
Kevin Windrem answered ·

There are other steps you probably need to do to bring up the interface and connect it to the rest of Venus OS. As of Venus OS v2.90, much of this is already done but it's not 100% for hats or slcan USB interfaces.

Prior to v2.90, you had to do a ip link set can0 up and also start services related to the interface.

Just now I released v3.0 of VeCanSetup which may help or may provide assistance in doing your own mods.

2 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

christophlaib avatar image christophlaib commented ·

Hello

super work @Kevin Windrem ! many thx
what i don't get is how to set up the new 3.0 version for VenusOS 2.9x
In the Github the instructions point to the old version :
1664518641412.png- or am i missing something ?
how to set up latest and greatest VeCanSetup on my Raspi ?
cheers
Christoph

0 Likes 0 ·
1664518641412.png (38.4 KiB)
Kevin Windrem avatar image Kevin Windrem christophlaib commented ·
The easiest way to install is to use PackageManager which is part of SetupHelper. You need SetupHelper anyway to run the VeCanSetup setup script.

Check out the ReadMe for SetupHelper. It an be downloaded from GitHub then copied to the target and the setup script run or you can use the blind install mechanism.

0 Likes 0 ·
pierresmits avatar image
pierresmits answered ·

@Bathnm Thanks for the reaction.
demos | grep can shows:

root@raspberrypi2:~# dmesg | grep can
[   46.919715] can: controller area network core
[   46.938623] can: raw protocol

@Kevin Windrem
Thanks for the reaction and the new release of VeCanSetup.

As I (probably) mucked up the setup with manual adjustments, I generated a new Venus OS image (v 2.91) and started from scratch.

After implementing VeCanSetup v3.0, I initiated/installed the setup and executed the addition of the interface with

Choose action from list above or (cr) if done with changes: a hat

and selected: 2) Pican Hat (1-channel), and followed with:

Enter optional name for the CANbus port on this Hat (cr for none): can0

which resulted in:

Enter optional name for the CANbus port on this Hat (cr for none): can0
PiCAN Hat (1-channel)
  can0 (can8)  spi0.0

Install interface as shown above (y/n)?: y
adding CANbus hat
Hat configuration updated

CANbus interface definitions:
interface: hat ) PiCAN Hat (1-channel)
    can0 (can8) can8 spi0.0

Available actions:
  Add a USB interface (a <interface>)
  Delete existing interface (d <interface>)
interface may optionally be added to the action, (e.g. a hat or d 11)
USB interface must be 10 or greater
Hat interface should be entered as 'h' or 'hat'

Choose action from list above or (cr) if done with changes: 
installing CANbus ports
adding udev rules for hat
updating VeCanSetup udev rules
adding new CAN hat overlay to config.txt

new interfaces will not become active until after a reboot
adding VeCanSetup/setup to reinstallScriptsList
Reboot system now (y) or do it manually later (n): y
rebooting ...

After the reboot, I checked with dmesg and got the output as shown above.

Checking the config.txt file in /u-boot, I now have:

[all]
dtparam=spi=on
#### begin CAN overlay
# PiCAN CANbus Hat (1-channel)
# instantiates as can0 ONLY !!!
# use udev rules to rename
[all]
dtparam=spi=on
dtoverlay=mcp2515-can0-overlay,oscillator=16000000,interrupt=25,spimaxfrequency=500000
dtoverlay=spi-bcm2835-overlay
#### end CAN overlay

which seems to be partially correct, as the PiCAN-M hat has 2 ports (1 for nmea0183 as rs422 connector, and 1 for nmea2000 as CAN-Bus Micro-C connector). Ideally, I would like to see both available and usable. For more details regarding the board/hat, see PiCAN-M with CAN-Bus Micro-C and RS422 Connector + 3A SMPS — SK Pang Electronics Ltd

What I get from the documentation re the board/hat is that:

  1. I don't have following in the config.txt

    enable_uart=1
    dtparam=i2c_arm=on
    Should I add these two lines to the /u-boot/config.txt?

  2. raspi-config needs to used to configure the UART, which I can't do in Venus OS
    What I need to change (according to the documentation with raspi-config):
    Would you like the serial port hardware to be enabled? Answer: <YES>
    But to do this within Venus OS?
7 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

bathnm avatar image bathnm commented ·

I would focus on getting one thing at a time working. With the configuration from VeCanSetup v3.0, did the driver initialise, aka what did dmesg | grep can show.

What you pasted above implies that the driver never landed and can interface detected. All that was loaded is the can module, not the driver.

All you need to get the can working is this....

dtparam=spi=on

dtparam=spi=on dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25


Two things to check...

1) do you have the overlay in the /u-boot/overlays

2) the /etc/venus/gpio file, comment out all lines as you may have a clash between the GPIO setup that VenusOS wants and the interrupt that the board needs.

Once you have it running, you an re-enable the VenusOS relay and digital input GPIO's one line at a time. When the can interface files, you have a clash and cant use that PIN.


To allow you to use the serial interface, edit the file /etc/inittab file and comment out the getty line for the serial interface. That is all the raspi-config does (I believe)

0 Likes 0 ·
mattgas avatar image mattgas bathnm commented ·

Hi,

I had a very similar problem with Venus OS 2.90 and 2.91 on activating a PICAN2 hat. The interface won't show up until I commented out all lines in /etc/venus/gpio file as you suggested. Now it works, thanks a lot!

0 Likes 0 ·
bathnm avatar image bathnm mattgas commented ·
@mattgas which pin causes the issue? If you could share which line you commented out, it would benefit others.
0 Likes 0 ·
mattgas avatar image mattgas bathnm commented ·

sure...as long as line "9 in digital_input_4" is commented out, the interface is working.

0 Likes 0 ·
Kevin Windrem avatar image Kevin Windrem mattgas commented ·
The Raspberry PI gpio_list file I got from Rob Duthie some time ago had digital in 4 on GPIO 19 not 9 so maybe your file had a typo.
0 Likes 0 ·
bathnm avatar image bathnm mattgas commented ·
Interesting the standard gpis file from a fresh install has digital_input_4 on GPIO 19 and not 9. See


GPIO 19 however is used on the 2nd SPI bus. Looking ash the schematic it would seem that the hat is using SPI and therefore needs GPIO19 to work.

I would say that there is a GPIO pin conflict for the HAT and disabling Digital 4 as you have done solves the problem.

0 Likes 0 ·
Kevin Windrem avatar image Kevin Windrem commented ·

Part of VeCanSetup is a check for GPIO conflicts in gpio_list. Detected conflicts prevent adding the interface. If all is well, VeCanSetup is silent on this subject.

The latest version of RpiGpioSetup provides an alternate set of GPIO assignments for relay outputs and digital inputs but that uses the i2c GPIOs so would probably conflict with your serial port.

You may need to eliminate some of the relays and/or digital inputs from /etc/venus/gpio_list to make room for the hat resources. Note that removing relays and digital inputs in the middle of the list will create a shift. For example, if you remove relay 4, the definition for relay 5 is used for relay 4 and the definition for relay 6 is used for relay 5. So it's best to remove the last items in each list.

Getting everything working will most likely need some manual changes and you might be better off not using VeCanSetup.

Yes, you will need to manually add lines for the serial port. I have no idea how to do what Raspberry PI OS does from within Venus OS unless you can look to see what is added in Raspberry PI OS and duplicate them manually in Venus OS.

VeCanSetup assigns CANbus hats to can8 and can9 to avoid conflicts with automatic configuration of USB interfaces. Providing a custom name will NOT shift the actual port!! So make sure you are doing tests on can8 NOT can0.

0 Likes 0 ·
pierresmits avatar image
pierresmits answered ·

Having added following to the /u-boot/config.txt manually (to ensure that the nmea0183/RS422 can work:

enable_uart=1
dtparam=i2c_arm=on

and rebooting the system did not lead to success.

It looks like that we need the serial port hardware enabled for the nmea0183 connector/port

2 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

bathnm avatar image bathnm commented ·
How are you testing the serial interface?
0 Likes 0 ·
johnny-brusevold avatar image johnny-brusevold commented ·

@PierreSmits You can try with modprobe i2c_dev in terminal and see if that module is loaded. On my pi with 2.90 and i2c mcp3424 I have to add this in modules

EDIT

Didn't read the whole thread but thought it was i2c based. If spi it is another kernel module spidev

0 Likes 0 ·
pierresmits avatar image
pierresmits answered ·

First of all: thanks to all who provided feedback and their insights.

My apologies to all, for my late reaction. Have been under the weather a bit.

But, yay!! Got the first part of the setup working (nmea2000 input)

This is what I did:

  1. again a clean install of VenusOS (better safe than sorry, re mucked up config possibilities)
  2. manually edited /u-boot/config.txt, added:
    [all]
    dtparam=spi=on
    dtparam=i2c_arm=on
    # Bring up the PiCAN controllers.
    dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
    dtoverlay=mcp2515-can1,oscillator=16000000,interrupt=24
    dtoverlay=spi-bcm2835-overlay
    
    
  3. rebooted the setup

After the reboot, I noticed in the GUI under services that can0 was live. And dmesg | grep can gave me:

root@raspberrypi4:~# dmesg | grep can
[    5.050240] mcp251x spi0.0 can0: MCP2515 successfully initialized.
[   12.397612] can: controller area network core
[   13.002624] can: raw protocol
[   13.017345] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready

and ifconfig gave me:

can0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          UP RUNNING NOARP  MTU:16  Metric:1
          RX packets:123008 errors:0 dropped:0 overruns:0 frame:0
          TX packets:458 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:983869 (960.8 KiB)  TX bytes:2789 (2.7 KiB)

and candump can0 gave me a nice output from my nmea2000 connected GPS.

Unfortunately, I didn't see the other can bus (can1) come alive. The second connector on the hat is a RS422 interface for the nmea0183 protocol, and I don't have any of that here at home to test with.

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Kevin Windrem avatar image Kevin Windrem commented ·
The RS-485 portion of that hat is not a CANbus interface so it will never show up as such.

If you heed two CANbus interfaces there are several 2-channel hats out there or you can use USB CANbus adapters

0 Likes 0 ·
pierresmits avatar image
pierresmits answered ·

@Kevin Windrem Thanks for the reaction.
The PiCAN-M hat does not have a RS-485 connector, but rather a RS422 connector for nmea0183 data streams.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

polonioli68 avatar image
polonioli68 answered ·

is listed in the serial with ttys0

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.