How to configure/use sangaboard?

I’ve had a scope built for awhile now but haven’t had a lot of luck getting motors to work. I tried using the drivers that came with the 28byj-48 steppers and an arduino nano - and almost got it working…but the motors ran VERY hot and after just a minute or two I was worried about the possibility of the plastic deforming from the heat. So I never even tried getting the microscope software talking to the nano for stage control.

With time on my hands and a new hot air station I decided to order a couple of sangaboard PCB’s and build one up. I ran into a few minor issues (the Diodes diodes for D1-4 no longer appear to be available anywhere so I had to find suitable substitutes - and though I thought they were the same package size they don’t fit very well. F1 I did get the part listed in the BOM but it’s also too big for the footprint on the board and it took some fiddling to get it to sit in a way that I could actually work.)

But I do have a sangaboard v0.3 built and apparently functioning since if I plug it into my windows machine I see it identify as a “sangaboard v0.3” and I can connect to it over serial and it responds as expected to commands. I’ve even verified that I can get the motors to move with manual commands.

So now I’m trying to integrate it with the actaul scope, but not having much luck. When I connect with OpenFlexure ev it shows no stage connected. If I look in /var/openflexure/settings/microscope_configuration.json I see stage->type->“SangaStage” but stage->port is null

{
  "camera": {
    "type": "PiCamera"
  },
  "stage": {
    "type": "SangaStage",
    "port": null
  }
}

If I do a lsusb on the pi I see the vid/pid for the sangaboard but no name:

pi@microscope:/var/openflexure/settings $ lsusb
Bus 001 Device 004: ID f055:5ab0
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I’ve been searching for documentation on the sangaboard and/or how to interface it but so far am coming up empty. Is there something I’m missing here?

1 Like

If you have soldered up your own Sangaboard, your skills are far beyond mine.

Thanks @WilliamW, but it wasn’t all that difficult. Figuring out substitute parts for those that were out of stock or unavailable was far more difficult for me :slight_smile:

The combination of a cheap hot air station, a syringe of solder paste with a very fine tip, and a good magnifier make it pretty easy.

I may have a few extra boards as well. The minimum order from jlcpcb was 5 boards and I also ordered enough components to build all 5. 2 others are spoken for by friends but I have the last 2 and the components for them available and would be willing to sell them at cost. I may be willing to build them up and sell them for a little over cost - but want to get this one working before I commit to anything :smiley:

2 Likes

Hello Jason!
Do you have errors in dmesg output?

That’s very strange - we talk to it using pyserial, so it ought to show up as /dev/ttyUSB0 or /dev/ttyACM0 - could you try ls /dev/tty* with and without it plugged in? If it’s not showing up as a serial port, I am very perplexed - particularly as you must have burned the bootloader correctly for it to work with Windows and show up as a Sangaboard.

On the overheating issue, the drive electronics are more or less identical between the bundled driver boards and the Sangaboard - in both cases it’s just voltage control, so it’s important to only use 5v with 5v motors or they’ll overheat, but I suspect you’ll have figured that out already!

Here’s the dmesg output when I unplug/plug:

[   31.550936] usb 1-1.2: USB disconnect, device number 4
[   37.737094] usb 1-1.2: new full-speed USB device number 5 using dwc_otg
[   37.884314] usb 1-1.2: New USB device found, idVendor=f055, idProduct=5ab0, bcdDevice= 1.00
[   37.884324] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   37.884329] usb 1-1.2: Product: Sangaboard v0.3
[   37.884333] usb 1-1.2: Manufacturer: Unknown
[   37.885144] cdc_acm 1-1.2:1.0: ttyACM0: USB ACM device

So it looks like it’s showing up ok to the OS. Same with checking /dev/tty* ttyACM0 appears when the sangaboard is plugged in.

I also tried updating ofm “sudo ofm upgrade” and restarting as well as rebooting both with the sangaboard plugged in and waiting to plug it in later and then restarting.

I’m also using the latest code off git for the sangaboard - it reports as version v0.5.1

after restarting ofm with the sanga plugged in ‘ofm status’ returns:
pi@microscope:~ $ ofm status
● openflexure-microscope-server.service - Flask instance to serve the OpenFlexure Microscope API
Loaded: loaded (/etc/systemd/system/openflexure-microscope-server.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-08-07 07:58:28 MST; 13s ago
Main PID: 912 (python)
Tasks: 10 (limit: 1772)
Memory: 27.5M
CGroup: /system.slice/openflexure-microscope-server.service
└─912 /var/openflexure/application/openflexure-microscope-server/.venv/bin/python -m openflexure_microscope.api.app

Aug 07 07:58:33 microscope python[912]:    Use a production WSGI server instead.
Aug 07 07:58:33 microscope python[912]:  * Debug mode: on
Aug 07 07:58:33 microscope python[912]: INFO:werkzeug: * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
Aug 07 07:58:33 microscope python[912]: [2020-08-07 07:58:33,122] [MainThread] [INFO]  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
Aug 07 07:58:41 microscope python[912]: INFO:werkzeug:192.168.1.14 - - [07/Aug/2020 07:58:41] "HEAD /api/v2/streams/snapshot?1596812321115 HTTP/1.1" 200 -
Aug 07 07:58:41 microscope python[912]: [2020-08-07 07:58:41,239] [Thread-2] [INFO] 192.168.1.14 - - [07/Aug/2020 07:58:41] "HEAD /api/v2/streams/snapshot?1596812
Aug 07 07:58:41 microscope python[912]: INFO:werkzeug:192.168.1.14 - - [07/Aug/2020 07:58:41] "HEAD /api/v2/streams/snapshot?1596812321171 HTTP/1.1" 200 -
Aug 07 07:58:41 microscope python[912]: [2020-08-07 07:58:41,279] [Thread-3] [INFO] 192.168.1.14 - - [07/Aug/2020 07:58:41] "HEAD /api/v2/streams/snapshot?1596812
Aug 07 07:58:41 microscope python[912]: INFO:werkzeug:192.168.1.14 - - [07/Aug/2020 07:58:41] "GET /api/v2/streams/snapshot?1596812321171 HTTP/1.1" 200 -
Aug 07 07:58:41 microscope python[912]: [2020-08-07 07:58:41,322] [Thread-4] [INFO] 192.168.1.14 - - [07/Aug/2020 07:58:41] "GET /api/v2/streams/snapshot?15968123
p

It seems like the board works since I can see the motors move when I issue serial commands…and the OS seems to recognize it. Just ofm doesn’t.

I tried the test suggested here: Simple controller using Arduino Nano isn't recognized by Openflexure

And I get what appears to be a syntax error in the python library:
pi@microscope:~ $ python sangatest.py
Traceback (most recent call last):
File “sangatest.py”, line 1, in
from sangaboard import Sangaboard
File “/home/pi/.local/lib/python2.7/site-packages/sangaboard/init.py”, line 1, in
from .sangaboard import Sangaboard
File “/home/pi/.local/lib/python2.7/site-packages/sangaboard/sangaboard.py”, line 54
“baudrate”: 115_200,
^
SyntaxError: invalid syntax

(Note - the carat is actually pointing at the 115_200 not “baudrate” and when I open that file in an editor with color coding the 115_200 get one color of highlighting for the 115 and another for the _200. But I’m not familiar enough with python to know why this could be an error…it looks correct to me.)

Is there somewhere I should be looking for errors or logs from ofm to show why it’s not picking up on the sanga being connected?

From the stack trace it looks like you are using python2, but openflexure is using python3.7. To load the openflexure python virtual environment run:
source /var/openflexure/application/openflexure-microscope-
server/.venv/bin/activate

Then pip install the sangaboard package there. I suspect that will help with the syntax error test you are trying.

I am interested in buying one assembled. My setup with the nano controller has those guts outside the housing and is a bit messy.

I figured it was probably a python version issue.

Tried your suggestion but when I ‘pip install sangaboard’ after starting the virtual env I get the following error:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.7/site-packages/past'
Consider using the `--user` option or check the permissions.

As for an assembled board…let’s see if I can get this one working first :smiley: Also I’m in the US so shipping to the US is easy but shipping anywhere else could be a significant extra expense to keep in mind. It seems it’s ridiculously cheap to ship stuff here but sending stuff from here is crazy expensive.

First of all. Awesome that you got a v0.3 made and got the bootloader onto it. Nice to see you are using the customised bootloader :smiley:. I am not sure anyone else has followed my instructions for that, so happy to know that it worked!

So I think OpenFlexure Raspian should have the sangaboard library. As the virtual environment is not owned by the pi user you would need to run:

sudo pip install sangaboard

If you activate the virtual environment and run

python

to get an interactive python session and then run:

from sangaboard import Sangaboard
with Sangaboard() as sb:
    sb.move_rel([1000,0,0])

Do the motors move?

The eV issue I am not sure how to debug. @jc2450 do you have any ideas?

I really need to learn more Python :slight_smile:

I started the virtual environment and then ran ‘sudo pip install sangaboard’ which appeared to work.

I then started interactive python but upon entering “from sangaboard import Sangaboard” I got:

(.venv) pi@microscope:~ $ python
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sangaboard import Sangaboard
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Sangaboard' from 'sangaboard' (unknown location)

So still not sure what’s up with python.

I did confirm again that using the ardino serial monitor and issuing ‘mr 30 30 30’ I do see movement from the motors. Just…not having luck getting python to work.

:frowning:

Urg. I am stumped. This might be something special to do with how the python environment works in OpenFlexure Raspian. It has been a while since I actually used it and progress is happening fast, I really need to make myself a home microscope. I’ll send an email to Joel to ask him to have a look at the issue, see if he has any ideas.

Appreciate the attempts at help since I’m stumped too and my python knowledge is far too lacking to solve it myself!

I have had this install of openflexure raspian on here for a few months…I could try wiping it and starting over. Think it was mid-March when I installed it. I tried doing an ‘apt-get update’ ‘apt-get upgrade’ which updated a bunch of packages…but none that looked specific to ofm. I did see libpython as one of the packages that got updated…but things are still acting the same after the updates.

I think Joel has some automagical command:

ofm upgrade

But yeah there have been quite a few changes to the Sangaboard library since march as there were a bunch of bugs we squashed. Downloading the newesr OpenFlexure Raspian would be a good idea.

If you’re working on anything other than the OFM server code, please don’t use the ofm virtual environment.

You should just be able to call python3 or pip3 from bash to get into the system Python environment and work there, or create a new virtual environment for your project.

As mentioned above, please don’t work in the ofm environment. The default user doesn’t have permissions to prevent accidentally mangling the ofm software.

If you call pip3 and python3 that should fix your Python 2 related issue.

If you run pip3 install sangaboard that should work.

For the sake of debugging, I think downloading the latest Raspbian OpenFlexure and using that as a fresh install is a really good shout. As Julian mentioned we did a lot of updates to the Sangaboard software not that long ago so that might help.

Ok. I appreciate all the help everyone!

So - pip3 install sangaboard as the pi user got the test script working…though I only see one motor (the x motor) move when I run it. I know Z and Y work though since I’ve seen them move when giving direct serial commands so I assume that the test script from @j.stirling is only meant to move X.

I’ll go ahead and start from a clean raspbian this afternoon and see how that helps. I figured doing ‘sudo ofm update’ and apt-get upgrade would handle getting everything up to spec…but starting clean seems to make a lot of sense at this point.

Great to know the command worked

sb.move_rel([1000,0,0])

is 1k steps in x. For y

sb.move_rel([0,1000,0])

For z:

sb.move_rel([0,0,1000])

Let us know how the clean new SD card goes.

@j.stirling - that makes sense. I thought the other elements were going to be something to do with acceleration or the like. Should have recognized that with three of them they were likely the axes!

And…good news reflashing with a fresh SD solved it. I now have the stage working!

Though I while I was able to figure out that the arrow keys worked for X/Y I haven’t yet figured out what the keyboard shortcuts are for focus and can’t seem to find docs for the GUI. But I’m sure I’ll figure that out this evening.

Thanks for the help everyone. Now to build up a board for my dad and then see if I can get the 2 extra spares working too :wink:

2 Likes

Fantastic. So cool to see one with a real Sangaboard!

For focusing you can use the scroll wheel of the mouse. I am not sure if there is a keyboard shortcut for autofocus yet, but it should be in a side menu somewhere.

There should be a little check box in the interface so you can mark this as solved.