How to MAKE it
Conceptual thoughts about the board
From the Inventoy I choose the IC HALL EFFECT SOT23 (
as provided by DigiKey), which is also part of the Fab.lbr for Eagle.
Digikey links also to the
datasheet which gives details about the Package LH SOT23W Pin-out.
Ver 1: InputHall PCB
First, I designed a board, based on Neils but added leds to show data flow (MISO, MOSI).
However, before milling it I got in discussion with
Daniele who is working with us at FabLab Kamp-Lintfort and I changed my board accordingly. Following is a summary of thoughts and discussion:
Ver 2: ADCInput PCB (alternative Design)
The attiny45 does not have "real" searial communication. It is not full-duplex. You can read from RX (PB2). Neil implemented a software-serial communication that works with 9600 baud (see neils code on
Input Devices).
So, Neils board has low-boud-rate serial OUTPUT communication.
If you want to use the serial library of the Arduino, you need to implement software-serial communication.
We checked if flashing the 45 enables soft serial communication. It does. But it will be slow: >9600 baud max if you use c code or >4800 baud max if you want to use the arduino serial communication. (The attiny85 would be able to work on 9600 baud max)
Benefits of serial communication:
- Software serial can be used when you have different voltages of differnt boards, communication with each other.
- You do not necessarily need an external clock.
Thats why I modified the board and added wired RTX to the FTDI connector, for initialization and later use of the Arduino serial communication library. Later, this still will be software-based serial communication but works under the hood and feels like typical serial communication (in the arduino environment).
For stable measurements and communication I added a crystal (16Mhz) to the board.
I also wanted to have full duplex communication in my final design for the final project (for safety reasons).
In principle I understand that one can scale down the board according to constraints (e.g. power consumption, board size, etc.) but in my scenario I don't need this.
I did some simple calculations about the speed and the requiremed baud rate to determine if the attiny45 fulfils my requirements.
I assumed a maximum speed of 10 km/h that I want to drive with the
fabKickBoard
max. 10km/h = 10.000m / 3600s = 2.777m/s
Im my setting: 2,7777m/s / 0.11m = 24.54 rotations per second
ADC3 has a 10-Bit resolution
So I have to send 2 Bytes * 25 = 50 Bytes per second (for 10km/h).
A baudrate of 9600 is capabe of 9600/8 = 1200 bytes per second.
So, the attiny44 will fulfill my requirements.
According to the results I started re-wiring the board. By doing this I checked the data sheet of the attiny 45 pin layout, ACD resolution, etc.
- because I need PB3 and PB4 for the external crystal (XTAL1&2) I need to modify the wiring.
- MISO and MOSI will be used for RXD and TXD.
- PB2 will become analog input for the hall sensor.
HOWEVER: to ensure that it will not interfere with the SCK while having the ISP cables connected for programming, I thought about adding a jumper pin to manually open and close the connection to the hall sensor.
Then, I thought about the placement of the sensor for my final project. I want to measure the speed (rpm) of the tire. Actually, all components on the board will be facing upwards. As a consequence, I have to bring the board especially the hall sensor as close as possible to the magnetic field I want to measure. This means, the board will be close to the tire - maybe too close so that dust, dirt, little stones may kill the board.
Thus, to me, it might make sense to decouple the hall sensor from the PCB.
And I did.
While layouting the board I also got rid of the extra jumper mentioned above. I simply use SCK from the ISP connector.
Another idea came to Daniele's mind: what if I can measure the magnets of the outrunner directly? It this works, I dont need to add a magnet to the tire, etc. Well, we will see later if that works.
Fabricating the board
List of components:
- 1x Attiny45
- 2x LED
- 2x Resistor 499
- 1x Resistor 10k
- 1x Capacitor 1uF
- 2x Capacitor 22pF
- 1x Quarz 16Mhz
- 3x 1x1 Pinheader (1 and a pair of 2: analog signal and VCC+GND)
- 1x 2x3 Pinheader (ISP-connector)
- 1x Pinheader (FTDI-connector)
This time, I used fabModules to mill the board while using the Roland MDX40.
Parameters I used in fabModules:
send command: mod_lp.py /dev/usb/lp0
server: 192.168.102.134:12345
Here, z0 was set to -85.67
BUT cut depth (mm) was set to 0.
Some hints:
- Be careful when setting z0. zjog (mm) will automatically be set to a value. Always type 0 there.
- If you dont, MDX40 will go into view-mode (you have to manually press the 'view' button to release).
- You cannot stop the job using fabmodules.
- You have to press reset on the machine, when you want to cancel a job.
- Have a look on the colour of the dust. If it is white, you are too deep. It needs to be a mixture of copper and white.
Programming the board
- Open Arduino IDE.
- Load ArduinoISP from examples.
- Connect Arduino via USB to computer.
- Upload ArduinoISP to the board.
- Connected the Arduino to the ADCIputBoard. Pins MOSI, MISO and SCK are digital pin 11, 12 and 13. RST is pin 10.
- Burn the bootloader to the board.
- Write code you want to upload to the ADCInputBoard ...
Because my board has no hardware serial communication I have to use software serial communication.
Also, I want to use Arduino standard libraries for serial comunication. So I have to map the pins according to this scheme:
Following are the mappings in the code:
// set RX TX for serial communicaton
const byte rxPin = 1; // RXD = PB1 = 1
const byte txPin = 0; // TXD = PB0 = 0
// set up a new software serial object
SoftwareSerial mySerial ( rxPin, txPin);
To read analoug input I have to map the pin, too.
// to read from ADC
int inputPin = A1; // PB2
- Then connect ADC, GND and VCC from ADCIputBoard
- Choose AtTiny from Tools->Board in the Arduino IDE.
- Choose sketch you want to upload.
- Choose Sketch->Upload Using Programmer.
As I use SCK as SHARED PIN .... remove SCK from ISP header of the ADCIputBoard (because it is used as shared pin with PB2 to read analog input)
Connect FTDI Cable and open serial monitor. Select the baudrate of 4800.
If you face problems with serial ouput, such as strange characters, first try to changed RX with TX or check the baud rate.
Finally, I still did not recieve all mySerial.print() outputs. It is an indcator for to much output. Thus, I reduced debugging outputs to a minimum and finally,
it worked.
/*
* AUTHOR: Rob van den Tillaart; modified Ralph Martin; modified by Karsten Nebe
* DATE: 2016-05-30
* ORIGINAL URL: http://playground.arduino.cc/Code/HallEffect
*
* PURPOSE: use an A1301 or A1302 as magnetometer
*
* Pin Layout LH Package
* =====================
* 1 VCC 5V
* 2 signal connected to Analog 0
* 3 GND
*
* Pin Layout UA Package
* =====================
* 1 VCC 5V
* 2 GND
* 3 signal connected to Analog 0
*
*/
#include <SoftwareSerial.h> // we need to establish software serial communication
#define NOFIELD 505L // Analog output with no applied field, calibrate this
// check this link for mapping of Arduino and AtTiny45 pins http://orig06.deviantart.net/82c9/f/2013/038/3/7/attiny_web_by_pighixxx-d5u4aur.png
// set RX TX for serial communicaton
const byte rxPin = 1; // RXD = PB1 = 1
const byte txPin = 0; // TXD = PB0 = 0
// set up a new software serial object
SoftwareSerial mySerial ( rxPin, txPin);
// to read from ADC from pin 7 of the AtTiny (PB2)
int inputPin = A1; // PB2
long compensated;
long gauss;
int raw;
// Uncomment one of the lines below according to device in use A1301 or A1302
// This is used to convert the analog voltage reading to milliGauss
//#define TOMILLIGAUSS 1953L // For A1301: 2.5mV = 1Gauss, and 1024 analog steps = 5V, so 1 step = 1953mG
#define TOMILLIGAUSS 3756L // For A1302: 1.3mV = 1Gauss, and 1024 analog steps = 5V, so 1 step = 3756mG
void setup()
{
mySerial.begin(4800);
}
void DoMeasurement()
{
// measure magnetic field
raw = analogRead( inputPin ); // Range : 0..1024
mySerial.println(raw);
compensated = raw - NOFIELD; // adjust relative to no applied field
gauss = compensated * TOMILLIGAUSS / 1000; // adjust scale to Gauss
/*
mySerial.println(gauss);
if (gauss > 0) mySerial.println("(S)");
else if(gauss < 0) mySerial.println("(N)");
else mySerial.println("*");
*/
if(raw > 800) raw = 800;
else if(raw < 200) raw = 200;
}
void loop()
{
delay(10);
DoMeasurement();
}
Downloads
ADCInputBoard & InputHall as Eagle files and with png's for fabModules
Code to test the HallSensor with the ADCInputBoard (including soft-serial communication