Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from raihei/ams-button
Browse files Browse the repository at this point in the history
sync with main
raihei authored Jan 27, 2025
2 parents 55844e6 + f0113b0 commit ab6fb28
Showing 6 changed files with 357 additions and 5 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -12,6 +12,30 @@

---

"ams-button"-Branch:<br>
Bambu AMS support via a touch button for selecting the desired AMS slot (or the manual feed slot)<br>
For LED feedback of the selected slot 4 WS2812 LEDs should be connected.<br>
Adjust the sensitivity of the touch button in conf.d/touch.aml line 10, if required<br>
(Set conf.d/touch.aml line 2 to "True" to enable display of touch button values in logger)<br>

At the moment, only the target esp32-s3-zero.yaml contains the required configuration.<br>
(Add substitution "touchbutton_ams_1" and package "touch: !include conf.d/touch.yaml" to other targets to enable.)<br>


Tested on BambuLab P1S with one AMS.<br>

Workflow:<br>
<ul>
<li>Press the touch button to select the desired slot (1-4 times)</li>
<li>LEDs will indicate number of touches (slot) in yellow </li>
<li>After 3 seconds, LEDs will change to green, to confirm selected slot</li>
<li>Scan spool within 20 seconds.</li>
<li>LEDs will start breathing green as confirmation.</li>
<li>Install spool in AMS within 120 seconds and confirm by pressing button again.</li>
<li>Spool data will be transfered to the printer</li>
<li>End.
</ul>


# 📖 [OpenSpool.io](https://openspool.io)

25 changes: 25 additions & 0 deletions firmware/conf.d/led-external.yaml
Original file line number Diff line number Diff line change
@@ -20,6 +20,14 @@ light:
name: Rainbow
speed: 25
width: 15
- addressable_lambda:
name: Breathing Green
update_interval: 10ms
lambda: |-
static float b = 0;
b = (sin(millis() / 500.0) + 1.0) / 2.0 * 0.6 + 0.4;
auto color = esphome::light::ESPColor(0, uint8_t(255 * b), 0);
it.all() = color;
- addressable_lambda:
name: Breathing Blue
update_interval: 10ms
@@ -28,6 +36,14 @@ light:
b = (sin(millis() / 500.0) + 1.0) / 2.0 * 0.6 + 0.4;
auto color = esphome::light::ESPColor(0, 0, uint8_t(255 * b));
it.all() = color;
- addressable_lambda:
name: Breathing White
update_interval: 10ms
lambda: |-
static float b = 0;
b = (sin(millis() / 500.0) + 1.0) / 2.0 * 0.6 + 0.4;
auto color = esphome::light::ESPColor(uint8_t(255 * b), uint8_t(255 * b), uint8_t(255 * b));
it.all() = color;
- addressable_lambda:
name: Apple Breathing
update_interval: 10ms
@@ -122,6 +138,15 @@ script:
red: 100%
green: 100%
blue: 100%
- id: set_led_semioff
then:
- light.turn_on:
id: neopixel_light
effect: none
brightness: 50%
red: 0%
green: 0%
blue: 0%
- id: set_led_off
then:
- light.turn_on:
17 changes: 12 additions & 5 deletions firmware/conf.d/pn532_rfid-solo.yaml
Original file line number Diff line number Diff line change
@@ -107,11 +107,18 @@ pn532_spi:
- binary_sensor.is_on: rfid_reader_spi_0_tag_is_openspool
- binary_sensor.is_on: rfid_reader_spi_0_tag_parsed
then:
- mqtt.publish:
topic: !lambda 'return "device/" + id(bambu_serial_number).state + "/request";'
# 255 = external ams, TODO: A1,P1,X1 might use different values for AMS
# 254 = external tray, first filament slot is tray 0
payload: !lambda "return bambulabs::generate_mqtt_payload( id(filament_raw_data0).state, 255, 254 );"
- if:
condition:
- lambda: 'return id(ams_scan_mode) == true;'
then:
- script.execute: start_timer_spoolinstall
- lambda: 'id(scanned_tag_data) = id(filament_raw_data0).state;'
else:
- mqtt.publish:
topic: !lambda 'return "device/" + id(bambu_serial_number).state + "/request";'
# 255 = external ams, TODO: A1,P1,X1 might use different values for AMS
# 254 = external tray, first filament slot is tray 0
payload: !lambda "return bambulabs::generate_mqtt_payload( id(filament_raw_data0).state, 255, 254 );"
text_sensor:
- platform: template
name: "NFC Raw Data"
238 changes: 238 additions & 0 deletions firmware/conf.d/touch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
esp32_touch:
setup_mode: False
measurement_duration: 0.25ms

binary_sensor:
- platform: esp32_touch
id: touchbutton_ams_1
name: "Touch button AMS 1"
pin: ${touchbutton_ams_1}
threshold: 100000
on_press:
then:
- if:
condition:
and:
- not:
script.is_running: timer_slotselect
- not:
script.is_running: timer_spoolscan
- not:
script.is_running: timer_spoolinstall
then:
- logger.log: "Keypress detected. Waiting for further key presses."
- script.execute: start_timer_slotselect
- script.execute:
id: set_led_yellow
led_number: 0
else:
- if:
condition:
script.is_running: timer_slotselect
then:
- globals.set:
id: slotselect_timeout
value: "0"
- if:
condition:
lambda: "return id(slotselect_counter) < 4;"
then:
- globals.set:
id: slotselect_counter
value: !lambda "return id(slotselect_counter) + 1;"
- logger.log: "Further key press detected."
- script.execute:
id: set_led_yellow
led_number: !lambda "return id(slotselect_counter) - 1;"
else:
- globals.set:
id: slotselect_counter
value: "1"
- logger.log: "Button pressed more than 4 times. Aborting."
- script.execute:
id: set_led_red
led_number: -1
- script.stop: timer_slotselect
- delay: 1s
- script.execute:
id: set_led_white
led_number: -1
- if:
condition:
script.is_running: timer_spoolinstall
then:
- logger.log: "Transfering spool data to printer"
- script.stop: timer_spoolinstall
- light.turn_on:
id: neopixel_light
effect: none
- script.execute:
id: set_led_green
led_number: -1
- delay: 500ms
- script.execute:
id: set_led_white
led_number: -1
- mqtt.publish:
topic: !lambda 'return "device/" + id(bambu_serial_number).state + "/request";'
payload: !lambda "return bambulabs::generate_mqtt_payload( id(scanned_tag_data), 0, id(slotselect_counter) - 1 );"
- globals.set:
id: ams_scan_mode
value: "false"
- if:
condition:
script.is_running: timer_spoolscan
then:
- logger.log: "Key pressed without scanning spool. Aborting"
- script.stop: timer_spoolscan
- globals.set:
id: ams_scan_mode
value: "false"
- script.execute:
id: set_led_white
led_number: -1

globals:
- id: slotselect_timeout
type: int
initial_value: "0"
- id: slotselect_counter
type: int
initial_value: "0"
- id: slotselect_display_counter
type: int
initial_value: "0"
- id: ams_scan_mode
type: bool
initial_value: "false"
- id: spoolinstall_timeout
type: int
initial_value: "0"
- id: spoolscan_timeout
type: int
initial_value: "0"
- id: scanned_tag_data
type: std::string
max_restore_data_length: 160
initial_value: ""

script:
- id: timer_slotselect
then:
- while:
condition:
lambda: "return id(slotselect_timeout) < 3;"
then:
- globals.set:
id: slotselect_timeout
value: !lambda "return id(slotselect_timeout) + 1;"
- logger.log: "Waiting for further key presses."
- delay: 1s
- logger.log: "Key press timeout."
- logger.log:
format: "Selected slot: AMS 1 slot %d "
args: [ 'id(slotselect_counter)' ]
- logger.log: "Waiting for spool scan (Timeout in 20 seconds)"
- globals.set:
id: ams_scan_mode
value: "true"
- repeat:
count: !lambda "return id(slotselect_counter);"
then:
- logger.log: "green repeat"
- script.execute:
id: set_led_green
led_number: !lambda "return id(slotselect_display_counter);"
- globals.set:
id: slotselect_display_counter
value: !lambda "return id(slotselect_display_counter) + 1;"
- script.execute: start_timer_spoolscan
- script.stop: timer_slotselect

- id: start_timer_slotselect
then:
- globals.set:
id: slotselect_timeout
value: "0"
- globals.set:
id: slotselect_counter
value: "1"
- globals.set:
id: slotselect_display_counter
value: "0"
- script.execute: timer_slotselect

- id: timer_spoolinstall
then:
- while:
condition:
lambda: "return id(spoolinstall_timeout) < 120;"
then:
- globals.set:
id: spoolinstall_timeout
value: !lambda "return id(spoolinstall_timeout) + 1;"
- logger.log: "Waiting for spool install confirmation."
- delay: 1s
- logger.log: "Spool install timeout!"
- globals.set:
id: ams_scan_mode
value: "false"
- script.execute:
id: set_led_red
led_number: -1
- delay: 1s
- script.execute:
id: set_led_semioff
led_number: -1
- delay: 500ms
- script.execute:
id: set_led_white
led_number: -1
- script.stop: timer_spoolinstall

- id: start_timer_spoolinstall
then:
- globals.set:
id: spoolinstall_timeout
value: "0"
- script.stop: timer_spoolscan
- logger.log: "Spool scanned. Please install spool and press button to confirm. (Timeout in 120 seconds)"
- delay: 1s
- script.execute:
id: set_led_breathing_green
led_number: -1
- delay: 2s
- script.execute:
id: set_led_breathing_green
led_number: -1
- script.execute: timer_spoolinstall

- id: timer_spoolscan
then:
- while:
condition:
lambda: "return id(spoolscan_timeout) < 20;"
then:
- globals.set:
id: spoolscan_timeout
value: !lambda "return id(spoolscan_timeout) + 1;"
- logger.log: "Waiting for spool scan."
- delay: 1s
- logger.log: "Spool scan timeout!"
- globals.set:
id: ams_scan_mode
value: "false"
- light.turn_on:
id: neopixel_light
effect: none
- script.execute:
id: set_led_white
led_number: -1
- script.stop: timer_spoolscan

- id: start_timer_spoolscan
then:
- globals.set:
id: spoolscan_timeout
value: "0"
- script.execute: timer_spoolscan
58 changes: 58 additions & 0 deletions firmware/esp32-s3-zero.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
esp32:
board: esp32-s3-devkitc-1

substitutions:
hide_ams_sensors: 'false'
led_pin: GPIO2
neopixel_pin: '48' #some boards have this on pin 38
touchbutton_ams_1: GPIO04

spi2_type: SPI2
spi2_clk_pin: GPIO10
spi2_miso_pin: GPIO11
spi2_mosi_pin: GPIO12

rfid0_spi_interface: SPI2
rfid0_ss_pin: GPIO13

rfid1_spi_interface: SPI2
rfid1_ss_pin: GPIO05

rfid2_spi_interface: SPI2
rfid2_ss_pin: GPIO06

rfid3_spi_interface: SPI2
rfid3_ss_pin: GPIO07

# rfid4_spi_interface: SPI2
# rfid4_ss_pin: GPIO05

# rfid5_spi_interface: SPI2
# rfid5_ss_pin: GPIO04

# spi3_type: SPI3
# spi3_clk_pin: GPIO18
# spi3_miso_pin: GPIO17
# spi3_mosi_pin: GPIO16

# rfid6_spi_interface: SPI3
# rfid6_ss_pin: GPIO15

# rfid7_spi_interface: SPI3
# rfid7_ss_pin: GPIO9

# rfid8_spi_interface: SPI3
# rfid8_ss_pin: GPI14 # TODO: Verify this is compatible

packages:
openspool-ams: !include openspool-ams.yaml
improv-serial: !include conf.d/improv-serial.yaml
#improv-bluetooth: !include conf.d/improv-bluetooth.yaml
#led-internal: !include conf.d/led-internal.yaml
extra: !include conf.d/extra.yaml
button: !include conf.d/button.yaml
touch: !include conf.d/touch.yaml

dashboard_import:
package_import_url: github://spuder/openspool/firmware/esp32-s3-zero.yaml@main
import_full_config: false
Binary file added images/esp32-s3-zero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ab6fb28

Please sign in to comment.