Support for the CAN BUS

Feature requested and implemented
Post Reply

Are you interested for the CAN BUS support in the Annex32 ?

Yes
12
75%
Don't care
3
19%
No
1
6%
 
Total votes: 16

cicciocb
Site Admin
Posts: 308
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 85 times
Been thanked: 197 times
Contact:

Support for the CAN BUS

Post by cicciocb »

Hi all,
this is a first experimental post that is supposed to create a poll on a subject.

The subject, and the question is : Are you interested for the implementation of the CAN BUS in the Annex32 ?
User avatar
Electroguard
Posts: 179
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 40 times
Been thanked: 102 times

Re: Support for the CAN BUS

Post by Electroguard »

Absolutely.
N7QWT
Posts: 6
Joined: Fri Feb 19, 2021 4:03 am

Re: Support for the CAN BUS

Post by N7QWT »

Yes please!
Been looking to start an open source Telematics project for my FIAT 500e, I have a close source unit now but when their server is down so is my remote monitoring and control of my car.
gianmagna
Posts: 9
Joined: Sun Feb 14, 2021 11:47 am
Has thanked: 4 times
Been thanked: 4 times

Re: Support for the CAN BUS

Post by gianmagna »

Ciao Francesco

I'm interested in understanding how to use the CANBUS.
I used two ESP32 D1 Mini modules connected to each other, I have the transmission on one but I do not receive anything on the other
it seems that ONCANBUS is not working well
I have used the examples to no avail.
I hope for your help, thanks
User avatar
Electroguard
Posts: 179
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 40 times
Been thanked: 102 times

Re: Support for the CAN BUS

Post by Electroguard »

I can confirm that CAN works great.

I have 3 pages of CAN articles I was in the process of doing, but didn't seem much point after the last project I published didn't even get an acknowledgement, so I just stepped back from it.
But here's one of them, which is a combined sender/receiver script which doesn't require any additional hardware other than the CAN transceivers, and uses the last byte of the devices IP address as the CAN node ID (although it can be changed using a textbox$ during operation if wished).

It's been a couple of months since I last used the script, and I've merely copied and pasted it below for you... so just remember that it was unfinished and still needed tweaking, and that I haven't run it for ages.

Once you're able to send via CAN using web controls it's easy enough to add some hardware.

Code: [Local Link Removed for Guests]

'Same CAN script but only one device will TX or RX at any time
'Local (RX) CAN ID defaults to the local IP node number, but can be changed
'Target (TX) CAN ID defaults to 631, but can be changed
'The local screen shows any local onHTMLchange component changes,
' so the slider changes the meter, and the buttons change the LEDs
'CANsend button sends current local values to the remote CAN device
' so both devices can interact via CAN to change outputs of each other
' first data byte is being used to send the Senders (TX) ID
localIP$   = WORD$(IP$,1)
nodeIP$    = WORD$(localIP$,4,".")
RXid = val(nodeIP$)    'this device
TXid = 631             'target device
canlength=0
ret = CAN.SETUP(500, 26, 5, 1) '500Kb/sec, TX, RX, mode, [filter]
if ret>0 then wlog "Error " + str$(ret): end
dim byte(8)
'senderID=0   'ID of sending device shown as last received sender by receiving device
s1=0         'web slider (0 to 255)
m1=0         'web meter  (0 to 255)
but1=0       'web button1
but2=0       'web button2
led1=1       'web LED1
led2=1       'web LED2
htmleventvar$=""
gosub screen
onhtmlchange screenchanged
oncanbus canRX
wlog "CAN " + nodeIP$ + " waiting..."
wait

screen:
cls
a$="<br>"
a$=a$ + "local CAN ID=" + textbox$(RXid) + "<br><br>"
a$=a$ + slider$(s1,0,254) + " " + meter$(m1,0,254) + "<br>"
a$=a$ + led$(led1)+" " + button$(" led 1 ",but1change) + "<br>"
a$=a$ + led$(led2)+" " + button$(" led 2 ",but2change) + "<br><br>"
a$=a$ + "target CAN ID=" + textbox$(TXid) + "<br><br>"
a$=a$ + " " + button$(" CANSend ",CANsend) + "<br><br>"
a$=a$ + "last received msg: byte0="+str$(byte(0))+", 1="+str$(byte(1))+", 2="+str$(byte(2))+", 3="+str$(byte(3))+", 4="+str$(byte(4))+", 6="+str$(byte(6))+", 7="+str$(byte(7))+"<br><br>"
html a$
return

screenchanged:
if htmleventvar$="s1" then m1=s1
refresh
return

but1change:
led1= 1-led1
refresh
return

but2change:
led2= 1-led2
refresh
return

canRX:
wlog "CAN msg received"
id=can.ident
wlog "ID="+str$(id)
if id=RXid then wlog "This is the correct target"
flags=can.flags
canlength=can.len
wlog "msg len="+str$(canlength)
for c=0 to canlength-1
 byte(c) = can.byte(c)
 wlog "byte " + str$(c) + " = " + str$(byte(c))
next c
senderID=can.byte(0)
m1=can.byte(1)
led1=can.byte(2)
led2=can.byte(3)
refresh
gosub screen
return

canTX:
CANsend:
'ret = CAN.WRITE( id, can_flags [,b0 [,b1 [,b2 [,b3 [,b4 [,b5 [,b6 [,b7 ]]]]]]]])
ret = can.write(TXid,0,RXid,m1,led1,led2,5,0,dateunix(date$),timeunix(time$)) 'b0 is being used to include senders ID
if ret >0 then wlog "Warning - transmit failure" else wlog "msg sent to ID " + str$(TXid)
return

end  '---------- End -------------

gianmagna
Posts: 9
Joined: Sun Feb 14, 2021 11:47 am
Has thanked: 4 times
Been thanked: 4 times

Re: Support for the CAN BUS

Post by gianmagna »

Hi Electroguard
in Annex32 WIFI RDS Help Version 1.43
the ONCABUS command is not called even in the TOPICS
I tried your program but to no avail
I have no errors in execution but the program stops at the next line "oncanbus canRX" I have two modules connected together
and I checked the transmission takes place but not the reception.
I have installed this Annex32 WiFi 1.43.3 CAN BLE version
If you kindly can help me make your program work
Post Reply