Bendlabs single-axis bend sensor

Using the Bendlabs 1-axis bend sensor with an ESP32 board

This post explores using a more tactile and sensitive type of flex sensor than I've used so far. This is part of my ongoing flex sensor assistive technology project.

The flex-sensor is the bendlabs 1-axis flex sensor.

In this post I show how I interfaced this sensor with an Unexpected Maker feather S2 board and started logging data from it. This board uses the ESP32 S2 MCU. The 'S2' variation has the feature that enables the board to appear as a physical keyboard. This will be useful to control communication software as part of the assistive technology project.

A short video showing the test system displaying real-time data can be viewed here:

A photo of the flex sensor from the Bendlabs website is shown below.

Bendlabs 1-axis flex sensor, from the bendlabs website.

A photo showing my grubby hand holding one of the flex-sensors is shown below. I already soldered the wires onto the end connector in this photo. The sensor comes without these.

Bendlabs single-axis flex-sensor.

To use these sensors you can either buy a development kit that Bendlabs sells which has the sensor and a board to plug it into or you can just buy the sensor and solder on your own wires to connect with your own board. I just bought the sensor. I need to be able to coonect this sensor to my own projects. If I can only get the sensor to work with a demo kit, it is not of much use to me.

I soldered on some silicone insulated wires to the end connector. The silicone allows the wire to be more flexible than the regular PVC insulation. This was a little tricky, but not too bad an exercise. I terminated the ends of the wires onto 0.1" header pins. The wires that I soldered onto the flex sensor and the header that they connect with can be seen in the photo below. On the left of the photo are the wires that connect to the Unexpected Maker Feather S2 board. I soldered female headers onto this board. Male or female headers on a development board? I've seen both. I went with female as I could and nobody stopped me.

Bendlabs single-axis flex-sensor with extension wires soldered on to break-out connector.

The pinout for the connector is shown below.

Bendlabs one-axis flex-sensor pinout.

The pinout shows that the signal interface is I2C - these are the SDA and the SCL signals. In addition to these, there are power (VCC) and ground (GND). The part is not 5V tolerant. I used the Unexpected Maker Feather S2 3.3V supply to connect with VCC. There are two other signals to deal with. nDRDY is 'not data ready' - meaning inverted logic on the data ready line. When data is ready, the line will go low. nRST is 'not reset', meaning that when this signal goes low, the sensor enters a reset condition. I connected these signals to two sockets on my board. nDRDY goes to pin 7 and nRST goes to pin 3. In the example code provided, nDRDY goes to pin 4, but I don't have a socket for pin 4, so I chose pin 7 and ajusted the software. More details on this below.

The wire colours that I used and their corresponding signals are:
1 black wire - GND ground
2 red wire - Vcc - 1.62-3.6V NOT 5V TOLERANT
3 green wire - nDRDY
4 blue wire - SDA - needs 10K pull up
5 yellow wire - SCL - needs 10K pull up
6 orange wire - nRST

The board I used has built-in 10K pullup resistors for the dedicated SDA and SCL ports. These pull-up resistors are necessary of I2C communication. I found that out the usual way that I find things out.

The Unexpected Makers Feather S2 board has a Qwiic connector socket which takes care of the power, ground, i2c clock and i2c signal lines. I bought a flexible wire Qwiic connector to attach the Qwiic connector socket on the board with the relevant signal lines on the flex sensor, using the 0.1" pins to connect the two devices.

I used the same colour wires from the flex sensor to the header pins as the Qwiic connector wires have that connect on the opposite side of the header pins.

Unexpected Maker Feather S2 board connected to a Bendlabs single-axis flex-sensor.

code

Demo code from Bendlabs can be found at:

Bendlabs one-axis flex-sensor Github.

This is written to run on the Arduino platform.

This code is aimed at the the Sparkfun Pro nRF52840 Mini. With the hardware abstraction that C allows, the example code compiles for the Unexpected Makers Feather S2 once you install the necessary ESP32 library. Have a search on t'net on how to install the ESP32 library.

The only update that I needed to make to the demo code is that I use pin 7 on my board instead of the pin 4 defined in the code for the nDRDY signal. I adjusted the corresponding line of code:

from

#define ADS_INTERRUPT_PIN  (4)

to

#define ADS_INTERRUPT_PIN  (7)

The quick start guide from Bendlabs says to use the C program 'bend_interrupt_demo' through the Arduino platform. I couldn't get this to work. I used my 'scope on the I2C lines. I could see clock signals on the clock line - SCLK, but no data on the SDA line. I did get the example program 'bend_polled_demo' to work with one correction. Hopefully, this will be corrected in the Github repository by the time that you read this post.

The line:

 int ret_val = ads_read_polled(&sample, &data_type);

should be

 int ret_val = ads_read_polled(sample, &data_type);

in the function:

void loop() {

  float sample[2];
  uint8_t data_type;

  // Read data from the one axis ads sensor
  int ret_val = ads_read_polled(&sample, &data_type);

After flashing the code to the board, I can see real time angle data plotting on the Serial Plotter in the Arduino IDE. See below for a screenshot.

Arduino serial plotter showing flex sensor data.

What next?

The positives of this flex-sensor are:

  • It is more flexible and tactile than the flex sensor I've used so far.
  • Works for positive and negative deflection.
  • More sensitive at detecting flex.

The negatives are:

  • Difficult to make an extension lead for. The soldering is finicky and there are 6 power and signal lines to contend with.
  • Cost. I'm not sure how much of an issue this is. The Bendlabs sensor costs around £40 at the time of writing. This is about double the cost of the other flex sensor I tested.

Bendlabs look to have a business model where they want to be consultants and customise their technology for each product. What I would like is an off the shelf 'plug and play' sensor and a lead with a socket on the end that the sensor plugs into. Hand soldering the leads onto the sensor presents a potential mode of failure, as well as being time consuming.

I will contact Bendlabs to see if they have something like this for sale.

Mounting an Android phone on Debian Linux to synchronise files

In this post I show how to mount the internal storage of an Android phone so that folders can be updated using e.g. FreeFileSync.

An Android phone can be automagically mounted using a file explorer such as Nautilus to copy and paste files. However I cannot use FreeFileSync to synchronise files to a folder on the phone.

This blog post explains a method that worked for me in December 2021 to solve this issue.

I tested this successfully on a Oneplus 6 phone running LineageOS enchilada (based on Android v11) and on a Sony G8411 running Android v9.

Install jmptfs

The tool I use is jmtpfs.

To install this in Debian:

sudo aptitude install jmtpfs

Create a directory to mount the phone's internal storage

We need to create a file to mount the Android phone in.

mkdir ~/tmp/phone

This creates a folder called 'phone' in your home directory in the subdirectory 'tmp'. You can name the folder anything else that you like.

Connect your Android phone to the Debian system

Connect your Android phone using a USB cable. For my phone running Lineage OS based on Android v11, I used the following to allow the internal storage to be accessible by the Debian system:

Go to settings.
Search on USB, select 'USB controlled by'.
On the next screen:
Select USB controlled: by 'This device' and use USB for: File transfer.

For the phone running Android v9, a message box comes up as soon as I connect the phone to the Debian system asking 'Allow access?'. Click on 'allow'.

The menu system in Android changes with each update, so the above instructions may not be accurate for your version of Android.

Mount the phone's internal storage

Back on your Debian terminal mount the phone's internal storage to the directory ~/tmp/phone using:

jmtpfs ~/tmp/phone

You should now be able to use the directory or subdirectories in ~/tmp/phone to sync with or move and delete files through the command line or file explorer.

Mounting under /media

For whatever reason, I could only get the method to work by creating the new folder under my home directory. I couldn't get it to work by creating a new folder under /media, even though I changed the ownership and group name of the directory I created to my username.

Marcel sent a comment to this blog that solves this for him, but I couldn't get the method to work on my system:

1) Change the group and user of the mount point (e.g. /media/phone) to a normal non root user
2) jmtpfs /media/phone (WITHOUT sudo )

Unmount the phone's internal storage

To end the session, exit from anything that is accessing the directory with the phone's internal storage in. Then unmount the directory using:

fusermount -u /tmp/mtp

Then unplug your phone.

Getting the unexpected makers esp32 s2 board to program from the Arduino IDE or CLI

Summary

Press the buttton marked 'BOOT' on the board while the board flashes.

Or:

Jumper GPIO0 to GND. After flashing, remove the jumper and press the RST button on the board.

Problem

Tyring to flash code to my shiney new Unexpected Makers feather esp32 s2 board I repeatedly get this error code:

serial.serialutil.SerialTimeoutException: Write timeout

This is thrown by the script esptool.py which is used to flash the target board.

Troubleshooting

I am using the Arduino IDE to try to build and flash a simple 'blinky' program.

I try using the arduino-cli command to manually build the source file and send the binary to the ESP32 S2 board.

Both methods fail with the same 'Write timeout' message, thrown by the file esptool.py. Fair enough, the IDE and the command line tools both use the same file, esptools.py, to program the board with.

I check that the serial port connecting my computer to the ESP32 S2 board exists using:

ls /dev/ttyA*

This returns:

/dev/ttyACM0

Unplugging the board causes this port to disappear, re-plugging it causes it to come back. So there is a serial port connection between the computer and the board.

I look for solutions on the web. On this stackoverflow answer I come across the idea of grounding GPIO0. The answer refers to an ESP8266 though. Worth a try.

I jumper GPIO0 to ground. Please see the photo below. I added the female header blocks to the board.The board programs from the Arduino IDE!

You need to press the RST button on the board after loading the code.

Unexpected Makers ESP32 S2 board with GPIO connected to GND

After figuring this out, I read up some more (see the section below). If I press the little button marked BOOT on the board while the code flashes, this also gets the board to program.

Explanation

I found an explanation of why this fix works in the esptool documentation

On many development boards with built-in USB/Serial, esptool.py can automatically reset the board into bootloader mode.

Not on this board.

The ESP32 will enter the serial bootloader when GPIO0 is held low on reset. Otherwise it will run the program in flash.

We need the bootloader mode, so GPIO0 needs to be held low.

Let's think about serial port signals. One good resource is this page.

GPIO0 has an internal pullup resistor, so if it is left unconnected then it will pull high.

There we go. By default, GPIO0 is high. So we need to tie it low to get to bootloader mode.

If you are using the jumper wire between GPIO0 and GND, to get it out of bootloader mode, the jumper needs to be removed and the RST button pressed.

Once I figured this out, I noticed the little button marked BOOT on the board. Pushing this while flashing the board also works.

The simplest serial interface needs three connections. Transmit, receive and ground.

A fuller implementation of the serial interface implements extra control signals such request to send (RTS), clear to send (CTS) and data terminal ready (DTR). Explaining how a serial connection is set up and controlled is beyond the scope of this post.

Reading further into the Espressif documents:

esptool.py is not able to reset your hardware automatically in the following cases: Your hardware does not have the DTR and RTS lines connected to GPIO0 and CHIP_PU (EN)

I suspect that the Unexpected Makers board is missing the DTR connection. I stand to be corrected though.