Mechanical Design

................................... &

...................................... Machine Design

Back to Mónica Pedro ←main page ←Assigments

Initial statements:

Our FCTFabLab Group decided to work at the same time Mechanical Design and Machine Desing.

    Mechanical Design group assignment:
   - design a machine that includes mechanism +  actuation  + automation
   - build the mechanical parts and operate it manually
   - document the group project and your individual contribution
    Machine Design group assignment:
    -  actuate and automate your machine
    - document the group project and your individual contribution

Machine - a 3D Scan


We planned to create a 3D Scan inspired on OpenScan but with some modifications, so that bigger obejcts can be scanned... anf for that we sow this another version of OpenScan V2

Actuation and Automation


We'd started looking into the OpenScan electronics, assembled the components in a breadboard so that the coding could start....

The OpenScan Hardware setup:

But we need to make some adjustments due to the actual FCT FabLab Inventory, namely:

Breadboarding ... to have a Programming environment

we had not all this components, but instead we'd to make some adaptations, such as related to local inventory.

So we discovered 2 equal stepper Motors but running at 7.4V and consuming 1A, so the proposed Drivers (A499) where not adequate since they provide a motor power supply of 8-35V), too much for the 7V found....

Here's the breadboarding goin on

First the Arduino Micro wired to:
  • RED - VCC
  • Orange - Motor Voltage
  • Blue - Motor Stepper
  • White - Motor Direction
We'll use only the Stepper and DIR of each of the 2 coils, so we organized each Stepper Motor as follows:
  • Coil 1 - Green + Black
  • Coil 2 - Red + Blue
  • and isolated the Two not used....
Finaly each of the Driver 4 pins to the corresponding Coil Pins
  • B1 - Black
  • B2 - Green
  • A2 - Red
  • A1 - Blue
And the DRiver VM to Breadbord V coming from Power supply.

Important things about each of the Parts....

Arduino Micro

based on the ATmega32U4 featuring a built-in USB

Main Specs:


Data Sheet

Need to know how the relation between them....

Driver DRV880

We'll use the DRV8880 Stepper Motor Driver Carrier

Main Specs:

Stepper Motor

The stepper Motors available in Fab Labs was the a Unipolar/Bipolar 7.4V, 1 A

Main Specs:


Stepper Motor's

Motor 1 - 360ºs

Motor 1 will work as a Plate, so I need to control its movements:

Motor 2 - Harm

Motor 2 will work as a Harm, so I need to control its movements:

Programming Environments

Writing simple and plain code... I's used SublimeText to create the basic code


We'll use the library AccelStepper directly instead of the OpenSCan code...

Important Pinouts

Motor 1 - 360º control

The first code to control motor in terms of Degrees...OpenScanMP_Motor1.ino

In the above code we defined the movement of 90º as shown in following video


EEPROM.h library reference

Enables the the read and write on EEPROM (memory whose values are kwpt when the board is turned off (like a tiny hard drive).

Different microcontrollers have different amounts os EEPROM, such as:



Wire.h library reference

This library allows you to communicate with I2C / TWI devices.

There are both 7- and 8-bit versions of I2C addresses. 
            7 bits identify the device, and the eighth bit determines if it's being written to or read from. 
            The Wire library uses 7 bit addresses throughout. 
            If you have a datasheet or sample code that uses 8 bit address, you'll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127. 
        The Wire library implementation uses a 32 byte buffer, therefore any communication should be within this limit. Exceeding bytes in a single transmission will just be dropped. 

But the Microcontroller we'll use has 7-bit I2C addresses

We'll also need to communicate with the RaspberryPi via I2C


How to stop everything when there's a HW interrupt (button or control switch)????

About interrupts

Interrupts are useful for making things happen automatically in microcontroller programs, and can help solve timing problems. Good tasks for using an interrupt may include reading a rotary encoder, or monitoring user input.

About Interrupt Service Routines

        ISRs are special kinds of functions that have some unique limitations most other functions do not have. 
            An ISR cannot have any parameters, and they shouldn’t return anything.
                an ISR should be as short and fast as possible
Nick Gammon’s notes on ATmega328P interrupts


External Interrupts

Possible Syntax:


Interrupt Numbers

we should use digitalPinToInterrupt(pin), rather than place an interrupt number directly into your sketch. The specific pins with interrupts, and their mapping to interrupt number varies on each type of board. Direct use of interrupt numbers may seem simple, but it can cause compatibility trouble when your sketch is run on a different board.

Atmega328P External Interrupts

External Interrupts can be configured to trigger on one of 4 states, here is a good documentation


Arduino reference to command
    Re-enables interrupts (after they’ve been disabled by nointerrupts(). 
        Interrupts allow certain important tasks to happen in the background and are enabled by default. 
            Some functions will not work while interrupts are disabled, and incoming communication may be ignored.
                Interrupts can slightly disrupt the timing of code, however, and may be disabled for particularly critical sections of code.

Syntax: interrupts()


Arduino reference to command
    Disables interrupts (you can re-enable them with interrupts()). 
        Interrupts allow certain important tasks to happen in the background and are enabled by default. 
            Some functions will not work while interrupts are disabled, and incoming communication may be ignored.      Interrupts can slightly disrupt the timing of code, however, and may be disabled for particularly critical sections of code.

Syntax: noInterrupts()


Arduino reference to command
        Turns off the given interrupt. 

Syntax: detachInterrupt(digitalPinToInterrupt(pin))(recommended)

Syntax: detachInterrupt(interrupt)(not recommended)

RaspberryPi Camera

Learning to work with the Raspberry Pi camera...

raspicam commands for Camera:

I'll need to take a pictures when a Command is sent from Main board...

take a picture and sabe in a file raspistill -o cam.jpg

but it was upside down.... so to flip it 180º

take a picture and sabe in a file raspistill -vf -hf -o cam2.jpg

Now I need to create a Bash script to take a picture and save it with the timestamp and store it in a folder named scanphotos

I used nano and created a file called

so the comand line sequence is:


chmod +x


and here is the picture taken

CRT + ALT + T .... sudo reboot enter

fundamental whem we miss up with Pi Camera and Camera Preview takes over the screen... with this we can reboot the system...

Here is a code that asks the user:

  1. Circular Degrees (1-360):
  2. Number of Photos in Circular (1 to Circular Degrees)
  3. Use Vertical Movement (YES/NO)?
  4. if YES

then takes a picture and name it acording to the Circular and Vertical movements

Python Code for our FCT 3D Scan

I2C between Raspberry Pi and Arduino....

to try-it out onse I'll follow this tutorial from

But the link to the I2C.Py file was broken so I'd to find another, does one: Raspberry-Pi-sample-code/

But the link to the I2C.Py file was broken so I'd not beem able to finishe this tutotial...

lets try another... raspberry pi and Arduino connected using i2c

Connecting Raspberry Pi 3 and Arduino


new concepts learned here:

remove I2C from Blacklist

blacklist: or blockslist is a basic access control mechanism that allows through all elements (email addresses, users, passwords, URLs, IP Addresses, domanin names, files hashes, etc), except those explicitly mentioned. Those itens on the list are denied access. The opposite is a whitelist which means only items on the list are let through whatever gate is being used....

install the i2c-tools...

        sudo apt-get install -y python-smbus
        sudo apt-get install -y i2c-tools

to check if the i2c is installed:

        sudo i2cdetect -y 1

what means this i2cdected output?

        It outputs a table with the list of detected devices on the specified bus.
        Each cell in the output table will contain one of the following symbols:
        "__" the address was probed but no chip answered
        "UU" Probing was skiped, because this address is currently in use by a driver. 
        "08" an addresss number in hexadecimal, e.g. "2d". A chip was found at this address...

Configure Arduino as Slave device for i2C

Arduino code DOWNLOAD

Uploaded the scketch and on the Raspberry looked for the IC2....

The Python code to Communicate...

was working on this code Pyhton code not working... need to look into the provided links...

        sudo apt-get update
        sudo apt-get upgrade
        sudo apt-get dist-upgrade
        sudo apt-get install python-smbus python3-smbus python-dev python3-dev
        sudo apt-get install i2c-tools

I'd looked into many examples and had been hable to receive and divide the String comming from Arduino in RaspberryPi3

Pyhton code Raspberry Pi 3 Master and Arduino UNO slave

With this code the string sent by Arduino UNO is decomposed into two separate parts, namelly DataLabel and Value

Arduino code Arduino UNO slave

Here I'm receiving the Request, but not able to identify the value, it's not yet a meanfull value...

Making Arduino understand the message sent by Raspberry Pi

Raspberry pi will send to Arduino two commands:

  1. Degrees for Circular Motor - integer of up to 3 digits
  2. Degrees form Vertical Motor- integer of up to 3 digits
  3. so the message will have the format of 6 integers
    1. 123456
    2. * as delimiter
  4. possible stream of data: 35010*120011*

Sending Char's from Raspberry - python

to be able to send a meaningful character I'll send the ASCI code of the character which is obtained with the Python function ord()

i2c.write_byte(slaveaddress, ord("x"))

Receiving Char's from Raspberry - Arduino IDE

So in the side of Arduino I'll need to converte the ASCI code of each character (coming in each byte) into a string which is obtained with the following block os code:

        int x =;
        c= x;                        // previously defined as char c;
        phrase = String(phrase + c); // previously defined as String phrase;

Now the question is how to convert a String into the neaningful numebrs, two integers of 3 digitis each...===?????

i2C with interrups

Interrupts in Raspberry Pi

i2C with interrupts
        sudo apt-get intall rpi.gpio

GPIO - raspberry-gpio-python

A Pyhton module to control the GPIO on a Raspberry

The first and and simplest way is to check the input value at a point in time. This is known as "polling" and can potentially miss an input if your program reads the value at the wrong time. Polling is performed in loops and can potentially be processor intensive. The other way os responding to a GPIO input is using "interrups" (edge detection). And edge is the name of a transition from HIGH to LOW (falling edge) or LOW to HIGH (rising edge).


Pull up / Pull down resistors

We have a input pin that will bring the signal from two switchs that will detect to the end positions Harm Motor, so to create a Closed loop.

But this input pins does not have hardware pull-ups so we could use RPi.GPIO module that allows to configure the Broadcom SOC to do this in software.

example of code to wait for a button press by pulling in a loop:

        while GPIO.input(channel) == GPIO.LOW:
            time.sleep(0.01) # wait 10 ms to give the CPU chance to do other things...Assuming that pressing the button changes the input from LOW to HIGH

Interrupts and Edge detection

An edge is the change in state of an electrical signal from LOW to HIGH (rising edge) or from HIGH to LOW (falling edge). For us its more important the change in state of the input than it's value. This change in state is an event.

To avoid missing a button press while our program is busy doing something else, there are two ways to get round this:

Interrupts in Motor's

Control Buttons that will indicate the end of Movement...

I'd added a Button on the BreadBoard to have the Hardware needed to create the code, which ideia is to use TWO switchs that will inetrrupt HARM MOtor if they reach them...

Two wires needed:

ARduino Code for 2 motors and 2 swithchs

Arduino IDE Code Download