Additional outputs using a SX1509B Expander
-
Hi everyone,
I have wired up a Sparkfun SX1509 (BOB-13601) to my Duet 2 WiFi.
The SX1509 is set to use the 0x71 I²C address (I double-checked it is indeed using 0x71 using a Arduino).
In my config.g I assign Ports to the Output pins like so:; GPIO Ports ; Create GPIO Ports on SX1509B expander pins M950 P5 C"sx1509b.0" ; Assign P5 to pin 1 M950 P6 C"sx1509b.1" ; Assign P6 to pin 2 M950 P7 C"sx1509b.2" ; Assign P7 to pin 3 M950 P8 C"sx1509b.3" ; Assign P8 to pin 4 M950 P9 C"sx1509b.4" ; Assign P9 to pin 5 M950 P10 C"sx1509b.5" ; Assign P10 to pin 6 M950 P11 C"sx1509b.6" ; Assign P11 to pin 7 M950 P12 C"sx1509b.7" ; Assign P12 to pin 8 M950 P13 C"sx1509b.8" ; Assign P13 to pin 9 M950 P14 C"sx1509b.9" ; Assign P14 to pin 10 M950 P15 C"sx1509b.10" ; Assign P15 to pin 11 M950 P16 C"sx1509b.11" ; Assign P16 to pin 12 M950 P17 C"sx1509b.12" ; Assign P17 to pin 13 M950 P18 C"sx1509b.13" ; Assign P18 to pin 14 M950 P19 C"sx1509b.14" ; Assign P19 to pin 15 M950 P20 C"sx1509b.15" ; Assign P20 to pin 16
Now the first issue is the number of pins, according to the Gcode dictionary (link) the Duet only supports up to 10 pins.
Is there another way, I could use those pins?Secondly, by using
M42 P5 S1
or
M42 P5 S0
I would expect the first pin on the SX1509B Port Expander to toggle the state of said pin, however nothing happens.
Any ideas?
Thanks! -
-
@alankilian true, but as far as I understand (see this note on the very same page this no longer works for RepRap Firmware 3.x
-
This post is deleted! -
@t0bias Yeah, I have no specific knowledge on this. Just trying to help.
Let us know when you figure it out.
-
Maybe use M122 and look for the I2C debugging information to see if your I2C is running properly?
I2C nak errors 0, send timeouts 0, receive timeouts 0, finishTimeouts 0, resets 0
-
Good point!
Unfortunately no luck here either..I2C nak errors 0, send timeouts 0, receive timeouts 0, finishTimeouts 0, resets 0
-
@t0bias Are the outputs set to open-drain by default or something?
(I'll go take a peek at the firmware to see how they are initialized next.)
-
Not that I was aware of..
However, I just checked the datasheet and according to it, all pins are configured as inputs upon power-on, so I think I would need to configure them as outputs. I don't really know what the duet firmware is doing internally here.. -
@t0bias said in Additional outputs using a SX1509B Expander:
I think I would need to configure them as outputs
When you say P5 instead of J5 it is configured as an output (I think).
Maybe add the "^" character to the M950 would do it?
C"name" Pin name(s) and optional inversion status, see Pin Names. Pin name "nil" frees up the pin. A leading '!' character inverts the input or output. A leading '^' character enables the pullup resistor. The '^' and '!' characters may be placed in either order.
-
I may be wrong, but I think pull-up resistors can only be enabled on ports of the Duet board itself.
There are source-files specifically for this expansion chip (here), however I have no idea what the "DuetNG" denomination is about to be honest. Also, this branch seems to be of the 2.x firmware only? -
@t0bias, which firmware version are you using? In particular, part of that code was rewritten between versions 3.2.2 and 3.3beta1, so what works in one might not work in the other.
I can increase the number of available GpOut ports in the next 3.3beta. Would 20 be sufficient?
-
@dc42 thanks for your reply. I am using version 3.1.1, would a upgrade fix the issue?
yes, 20 would be sufficient, maybe a bit more would be even better still? -
@t0bias said in Additional outputs using a SX1509B Expander:
@dc42 thanks for your reply. I am using version 3.1.1, would a upgrade fix the issue?
An upgrade to 3.3beta1 might possibly fix it, if it doesn't then let me know and I'll implement a fix in 3.3beta2.
yes, 20 would be sufficient, maybe a bit more would be even better still?
Memory is rather tight on the Duet 2, so I'll set it to 20 in 3.3beta2. It's already 32 on Duet 3 and 3 Mini.
-
I upgraded to 3.3beta1 today, but it still doesn't work unfortunately
-
Thanks, this is on my list to test/investigate.
-
I have just tested this, and ports sx1509b.0, .1 and .2 all work for me using RRF 3.2.2 and also using RRF 3.3beta1. I didn't test the other ports.
Points to note:
- M115 will report the SX1509B if it is detected:
04/03/2021, 11:17:06 m115 FIRMWARE_NAME: RepRapFirmware for Duet 2 WiFi/Ethernet FIRMWARE_VERSION: 3.3beta1 ELECTRONICS: Duet WiFi 1.02 or later + DueX5 + SX1509B expander FIRMWARE_DATE: 2021-02-14 16:00:49
- My test system includes a very old DueX5. On these old boards, the TWC and TWD pins are labelled the wrong way round on the 10-pin expansion header. They are also labelled incorrectly on the wiring diagrams at https://duet3d.dozuki.com/Wiki/Duex_wiring_diagrams for the 0.6 and 0.7 boards. On all DueX revisions, TWC (aka SCL) is next to the ground pin at the end of the header.
-
Strange, the SX1509B is in fact detected:
FIRMWARE_NAME: RepRapFirmware for Duet 2 WiFi/Ethernet FIRMWARE_VERSION: 3.3beta1 ELECTRONICS: Duet WiFi 1.02 or later + SX1509B expander FIRMWARE_DATE: 2021-02-14 16:00:49
however the pins don't get driven high (or low) using the M42 commands.
I am confident the I²C-Wiring is correct, since I tried using a MCP23017 based relay board that responds to I²C-Commands just fine.Any suggestions or ideas are highly appreciated!
-
@t0bias
Have you checked the I2C address?
It has to be set to 0x71Here some code to test it directly with M260
https://forum.duet3d.com/topic/13911/sx1509-on-maestro-does-it-work/3 -
@t0bias, if the board is detected then the I2C pins are connected correctly and the slave address is set correctly.
How are you testing the outputs of the SX1509B? I have connected each output through a 100 ohm resistor to one of the cathodes of a 2-digit common anode 7-segment display, with the anodes connected to +3.3V.