TWCManager
TWCManager copied to clipboard
RS485 CAN HAT - will it work?
Should it work with using that adapter on a Raspberry Pi Zero W?
https://www.waveshare.com/w/upload/2/29/RS485-CAN-HAT-user-manuakl-en.pdf
I just like that idea more than having something plugged in to USB which - in my case - would be out under a carport, living in Switzerland with -20 to +35deg C.
The adapter is "half duplex", if that makes the difference.
It should do, nothing in the documentation raises a red flag. RS485 is a half-duplex protocol so that won't cause you any issues.
I'm not sure if we have anyone else using that hat but if you do find it works well please let me know and I'll add it to the doco.
what a freakin' fast reply! Thanks so much! Will do, and will comment back, thanks again!
It worked fine for me :-) On both Rp0W, Rp3B, OrangePi. BTW: the uart_control tool can be very helpful ...
cool @M-VdM ! Thanks! What did you do with that uart-tool? Necessary to make it work? Did you change something in the configuration to make it work?
Hi @raffiniert - I have also used the waveshare with an RPi Zero W. I have documented my process so if you confirm what you have/haven't managed to do so far, I can send through some steps to you.
hey @Squazel , so far, I have... ordered and received the components :-) Nothing else. So knowing your steps would be awesome. Thanks in advance!
Sorry @raffiniert - I didn't get/see this message a few weeks back.
Here was my process - let me know if any questions.
- Acquire parts for project (sounds like you are done here, but just to make sure that we are dealing with the same stuff):
- Raspberry Pi Zero WH (Wi-Fi, with headers)
- Slim case for RPi Zero WH, with cutouts for pin access
- 8GB+ SDHC card (at least Class 1)
- Waveshare RS485 CAN HAT (Manual here: https://www.waveshare.com/w/upload/2/29/RS485-CAN-HAT-user-manuakl-en.pdf)
I also got the following parts as I have mounted the RPi inside the TWC/HPWC unit. You can always get the unit running outside of the TWC unit off a standard USB power supply, so this would be something to come back to only if needed later.
- A Micro USB connector to bare wires (chop a Micro USB cable in half is probably easiest)
- A step-down DC-DC transformer (UBEC, Buck) from 14V to 5V
- A section (20cm) of 10-way ribbon cable
- 1x Male IDC crimpable 10-way connector (e.g. https://au.rs-online.com/web/p/products/6741205/) - this is for the existing (hard-wired) ribbon cable to connect to our new extension
- 1x Female IDC crimpable 10-way connectors (e.g. https://www.jaycar.com.au/10-way-idc-line-socket/p/PS0984 - this is to connect to the LED board)
- Initialise the Raspberry Pi (sorry if these steps are more basic than you need - I just documented my whole process). I'm using Windows here, so if you're doing things on a Mac or Linux (or using a keyboard/screen connected directly to the RPi) then things will be different.
- Connect the Micro SD card to a (Windows) computer via a suitable SD card reader/adaptor
- Download and install the Raspberry Pi Imager from https://www.raspberrypi.org/software/operating-systems/
- Choose to install Raspberry Pi OS Lite (under the "Other" menu) onto the Micro SD card
- Reconnect/mount the Micro SD card again and do the following in the root of the boot (small, FAT32) partition/drive -- there will be a few partitions but Windows will only be able to open one of them (this is the one you want)
- Create an empty file ssh or ssh.txt in this partition
- Also create file wpa_supplicant.conf in this partition with the following content (replacing Wi-Fi network details with your own appropriately):
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=AU
network={
ssid="NETWORK-NAME"
psk="NETWORK-PASSWORD"
}
- Unmount the SD card and insert into into the Raspberry Pi
- Power the Raspberry Pi and wait for it to join the network
- Find its IP address (check your router) and then SSH into it using PuTTY or similar (default credentials are username
pi
, passwordraspberry
), and update password to something secure usingpasswd
- Configure the RS485 HAT:
- Turn off the RPi now
- Connect the RS485 CAN HAT to the RPi pins (when turned off), and then connect power to the RPi again
- SSH into the RPi again
- Install WiringPi:
sudo apt-get install -y wiringpi
- Confirm that the following gives you a response:
gpio -v
- Following https://www.waveshare.com/wiki/Libraries_Installation_for_RPi (adjusted slightly as it was a bit outdated) - install required libraries:
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.60.tar.gz
tar zxvf bcm2835-1.60.tar.gz
cd bcm2835-1.60/
sudo ./configure
sudo make && sudo make check && sudo make install
sudo apt-get update
sudo apt-get install -y python3-pip
sudo pip3 install RPi.GPIO
sudo pip3 install smbus
- Disable shell over serial connection (as per manual pages 13/14):
sudo raspi-config
Under "3 Interface Options" > "P6 Serial Port" set "Login shell" to No and Hardware to Yes Then Finish > Reboot: No - Check
/boot/config.txt
to ensure thatenable_uart=1
is present at the end of this file Can usetail /boot/config.txt
to do this
Modify config.txt pas per page 10 of the manual, noting the variation for the newer board with the 12M crystal as documented in https://www.waveshare.com/wiki/RS485_CAN_HAT:
echo "dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000" | sudo tee -a /boot/config.txt
- Then reboot:
sudo reboot
- And SSH back in, confirm that the RS485 board has initialised correctly:
dmesg | grep -i '\(can\|spi\)'
- Connect to TWC
- Turn your TWC(s) and RPi off
- Open the TWC(s) up and set to Slave mode
- Connect the CAN HAT A terminal to the positive terminal in the TWC's RS485 comms bus and B terminal to the negative terminal
- Note that there is a demo program available for the CAN HAT - I used this the first time after connecting it to the TWC/HPWC to make sure that it was receiving data correctly. I actually had the polarity wrong, so that was very useful. But probably safe to skip this for now and come back to it if you have issues later (I can provide details here later if needed).
- Install TWCManager
- Turn everything back on (TWC(s), RPi)
- Install TWCManager using instructions on this project
I did have a bit of trial and error along the way, so hopefully this helps you shortcut some of that pain. Happy to help if you get stuck along the way or if any of this doesn't make sense.
Cheers Michael
how awesome is that, @Squazel ! Thank you so much! Hope will have time to dig into soon...
@Squazel your instructions on configuring the RS485-HAT worked like a charm, thank you so much! Now if only I would succeed in installing TWCManager itself :-/
https://github.com/ngardiner/TWCManager/issues/406
Btw., I just drafted a small case to 3d print for the Raspi and HAT, if sme. needs it, let me know!
Ok, I succeeded with the installation, but now I get this when trying to up docker:
ERROR: for twcmanager Cannot start service twcmanager: linux runtime spec devices: error gathering device information while adding custom device "/dev/ttyUSB0": no such file or directory ERROR: Encountered errors while bringing up the project.
Ok, I changed in docker-compose.yml
devices: - "/dev/serial0:/dev/serial0"
Now I can, for the first time, start with sudo docker-compose -f docker-compose.yml up
However, I get no output to the console. No TWC connected so far, but just no output seems strange? Or doesn't this work when using docker?
Unfortunately I'm not yet using docker for mine (different issues and haven't had time to clear everything and start again) - but no reason that this shouldn't work, and I believe that you should get something to console if running in the foreground.
You could try running in the background (-d I think) and then checking logs with: docker logs docker_twcmanager_1
But that will probably be blank as well...
The only other difference I can see there is that your device is serial0, while mine is ttyS0. Not sure why that would be different if we have the same hardware, but doesn't sound like that's the main issue from the way you describe it.