Input Devices

In this lesson I design and fabricate a PCB with a light sensor which reads the intensity of light and glows a LED proportionately. I used KiCAD electronic design automation (EDA) libre software.

Design and fabricate a board with a light sensor

Install the necessary component libraries

I have had trouble constructing the Hello World board because I did not load the updated fab libraries to KiCAD. So now I am loading them from Emanuele Goldoni's Hello World with KiCAD tutorial. And then I have added my input device: an opto electric sensor (phototransistor).

The first thing I needed to do was importing the component libraries from Emanuele Goldoni (pretty, mod and lib). As Emanuele sugests:

Before importing the library, add the 3D model of the resonator (a Ceramic Abracon AWSCR made by Walter Lain and released under CC3-BY-SA / GPL3) into the KiCad 3d packages folder.

Extract the resonator_SMD.* files somewhere, move within this folder and from a Terminal type

sudo cp resonator_SMD.wrl /usr/share/kicad/modules/packages3d/Crystals.3dshapes/
sudo cp resonator_SMD.wings /usr/share/kicad/modules/packages3d/Crystals.3dshapes/

Then add the fab.pretty library from Emanuele Goldoni into the Pcbnew path.

 falta bildo  falta bildo

Add the components, labels and threads; anotate the components

This is my first design where I put a common ground to the RGB LED anode. I had to break this connection and link it to Vcc on the board.

 bildoj

The corrected design has Vcc on the RGB LED common anode.

 falta bildo

Control the electrical rules

 falta bildo

Asociate the component footprints

 falta bildo

Generate the netlist

 falta bildo

Trace the paths

First read the netlist

 falta bildo

It sets the components in the middle of the design space.

 falta bildo

I try to use the feature for automatic distribution of components.  falta bildo

 falta bildo  falta bildo  falta bildo  falta bildo

But it needs the board cuts (which I did not trace yet) in order to do it. Then I tryed spreading out the footprints.

 falta bildo  falta bildo

It did not work either. So I just placed the components, traces and cuts manually.

 falta bildo

This is the corrected circuit design image which I used on the output device lesson.

 falta bildo

Check the design rules

 falta bildo

Exporting the traces and cuts to SVG

 falta bildo

Printing the board with pcb2code

I have discovered a software in order to make the gcode locally. There is a pcb2code tutorial.

I used the same command except for the drill, which is not necesary.

pcb2gcode \
      --zero-start \
      --onedrill \
      --software linuxcnc \
      --tile-x 1 \
      --tile-y 1 \
      --front *-F.Cu.g* \
      --back *-B.Cu.g* \
      --front-output front.ngc \
      --back-output back.ngc \
      --metric \
      --zwork 0 --offset 0.2 \
      --zsafe 3 --zchange 40 \
      --mill-feed 500 \
      --mill-speed 6000 \
      --zdrill -3 \
      --drill-feed 500 \
      --drill-speed 6000

I had an error because I have not generated Gerber files. Besides, some of the parameters (such as --zero-start) are obsolete. Finally, I ran a reduced set without drilling:

pcb2gcode \
      --front *-F.Cu.g* \
      --front-output front.ngc \
      --metric \
      --zwork 0 --offset 0.2 \
      --zsafe 3 --zchange 40 \
      --mill-feed 500 \
      --mill-speed 6000

Then I had an error showing that the piece origin was outside of the milling space.

capture of wrong origin

I tried to generate gcode with the cut design. Nevertheless, it would generate an empty trace file.

Generating Gcode with Fabmodules

I decided to revert to Fabmodules and use PNG trace

PNG trace image

and PNG cut files.

PNG outline image

But then the PNG files have a size of 480.836 mm x 473.781 mm. They generate immense Gcode files on Fabmodules.

I reduced the size of the PNG files on Inkscape and generated the Gcode files on Fabmodules.

 falta bildo

This is the trace file

 falta bildo

And this is the cut file

 falta bildo

Fabricating the board

This is the photo of the finished board.

 falta bildo

Mods can also make the Gcode

At Mods it we right-click on an empty area.

 falta bildo

Upon selecting programs, we get to select to open server program.

 falta bildo

On the machines' G-code section, we select mill 2D png.

 falta bildo

With that Javascript program, we can open the traces PNG file.

 falta bildo

And obtain a G-code trace file.

 falta bildo

The same way we can generate a G-code cut file.

 falta bildo

Bill of materials

For a circuit that has a phototransistor and an RGB LED, beside the PCB, the following parts are needed.

AmtNamePart numberDescription
1Phototransistor1080-1380-1-NDPhototransistor 940nm Top View 1206 visible
5Resistor311-10.0KFRCT-NDRES 10.0K OHM 1-4W 1% 1206 SMD
1Capacitor445-1423-1-NDCAP CER 1UF 50V X7R 10% 1206-
1RGB LEDCLV1A-FKB-CK1N1G1BB7R4S3CT-NDLED RGB DIFFUSED 4PLCC SMD
1ResonatorXC1109CT-NDCER RESONATOR 20.00MHZ SMD
1Header 2x3609-5161-1-ND6 Positions Header Connector 0.100" (2.54mm) Surface Mount
1Header 1x6S1143E-36-NDSMT RT Angle Male Header 0.1" (36pos)
1MCU ATTiny44ATTINY44A-SSU-NDIC MCU AVR 4K FLASH 20MHZ 14SOIC-

Program the MCU to measure light intensity

I programmed the MCU to read the phototransistor and use the same value for the light intensity on the LED. My simple code in Arduino IDE contains something similar to this:

void setup() {
int val=0
}
void loop() {
val = analogRead(13); // read phototransistor input pin
analogWrite(12, val); // write LED output pin
delay(10); // wait some milliseconds for next reading
}

The code is in the Light intensity sensor program and it is described at the Embeded programming lesson.

This is the programmed board.

 falta bildo

Conclusions

I had doubts about my Hello World design because I had seen my oscillator had 2 contacts. But the Eagle Hello World tutorial said that it had 3 contacts. I did not understand where to place the other contact. I concluded that it would be connected to ground. So I looked in the local inventory if there were 3 contact oscillators. I found the 3 contact 20Mhz oscillator and the oscillator data sheet. This made me feel more confident of the choice of component.

I found synchronous detection fabulous for making very precise measurements. I thought what Neil showed in his synchonous detection example was applicable to my case. I needed to detect the difference in ambient light by having a separate phototransistor because I was not going to waste valuable RX time to contrast data detection with ambient light.

Sources

Input device board edges in Gcode with corrected polarization for RGB LED.
Input device board traces in Gcode with corrected polarization for RGB LED.
Phototransistor datasheet
RGB LED datasheet
Light intensity sensor program

Other photos

 falta bildo  falta bildo