Month: April 2015

Finalmente as partes fresadas para o Meu Primeiro CNC chegaram

Como vocês sabem estou desenvolvendo um CNC p/ fazer placas de circuito impresso e p/ fresar madeira e metais macios, como por exemplo alumínio.

A maior parte deste CNC é desenvolvida com peças padronizadas de mercado (produto de prateleira), mas algumas partes como a base X(cama ou bed em inglês), a base Z (base do spindle) e o adaptador p/ acoplar no suporte da castanha são peças customizadas. Estas peças são feitas em alumínio fresado.

Eu mandei fabricar estas peças na Torneamentos Pontone (não tenho nenhum vínculo com eles e nem estou recebendo p/ fazer propaganda deles, só estou divulgando aqui porque gostei da qualidade do serviço que eles prestaram). As peças foram confeccionadas nas seguintes ligas de alumínio com seus respectivos preços:

- Suporte Castanha - Alumínio Liga 6351
- 01 peça -  Valor unitário: 95,00

- Mesa CNC - Alumínio Liga 5052
- 01 peça -  Valor unitário: 295,00

- Base Spindle - Alumínio Liga 5052
- 01 peça -  Valor unitário: 169,00

Estas foram umas das peças mais caras até agora (a lista completa com todas as peças e custo estão nesta planilha: https://docs.google.com/spreadsheets/d/1Cw12JK1nSOURXnkiu8UeDRuR-VCACQ6kpZGtEg_TR5Q), mas estou prezando pela qualidade antes do preço. Esta liga de alumínio (5052) por exemplo é usada na indústria naval o que assegura uma melhor resistência.

Antes de montar o CNC resolvi desenha-lo usando o FreeCAD. Eu nunca havia utilizado esta ferramenta, mas o fato de ter vários vídeos tutoriais sobre ele no Youtube facilitou muito meu aprendizado. Outra vantagem dele é o fato de permitir usar a “Navegação” do padrão Blender, assim eu não precisei aprender a como usar o mouse e teclado no padrão nativo CAD.

Se eu não tivesse criado o projeto do CNC no FreeCAD eu teria cometido muitos erros de montagem. E pior, eu teria mandado fabricar algumas peças com dimensões erradas, mas que felizmente puderam ser detectadas facilmente na visualização 3D. Por isso é importante medir e desenhar todas as peças do projeto, mesmo que isso dê um pouco de trabalho.

Bom, chega de conversa, vamos ao que interessa: as fotos e screenshot do projeto.

Design do CNC no FreeCAD (dica: clique com o botão direto sobre a imagem e mande visualizar a imagem para ver no tamanho original) :

CNC_FreeCAD

Base X (bed) do CNC:

base_x

Base Z (spindle holder) :

base_z

Adaptador p/ Castanha:

ballnut_adapter

A três peças empilhadas:

stack_base

Base Z com a Tupia DeWALT D26670 parafusada:

basez_spindle

Base X com Tupia visão traseira:

basez_spindle_backview

É isso pessoal, em breve postarei mais novidade sobre a montagem do CNC.

SNMP Walking in the raspi berry pieee

$ snmpwalk 192.168.0.15 -c public -v1
SNMPv2-SMI::mib-2.1.1.0 = STRING: "Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l"
SNMPv2-SMI::mib-2.1.2.0 = OID: SNMPv2-SMI::enterprises.8072.3.2.10
SNMPv2-SMI::mib-2.1.3.0 = Timeticks: (7542) 0:01:15.42
SNMPv2-SMI::mib-2.1.4.0 = STRING: "Me "
SNMPv2-SMI::mib-2.1.5.0 = STRING: "raspberrypi"
SNMPv2-SMI::mib-2.1.6.0 = STRING: "Sitting on the Dock of the Bay"
SNMPv2-SMI::mib-2.1.7.0 = INTEGER: 72
SNMPv2-SMI::mib-2.1.8.0 = Timeticks: (87) 0:00:00.87
SNMPv2-SMI::mib-2.1.9.1.2.1 = OID: SNMPv2-SMI::snmpModules.10.3.1.1
SNMPv2-SMI::mib-2.1.9.1.2.2 = OID: SNMPv2-SMI::snmpModules.11.3.1.1
SNMPv2-SMI::mib-2.1.9.1.2.3 = OID: SNMPv2-SMI::snmpModules.15.2.1.1
SNMPv2-SMI::mib-2.1.9.1.2.4 = OID: SNMPv2-SMI::snmpModules.1
SNMPv2-SMI::mib-2.1.9.1.2.5 = OID: SNMPv2-SMI::mib-2.49
SNMPv2-SMI::mib-2.1.9.1.2.6 = OID: SNMPv2-SMI::mib-2.4
SNMPv2-SMI::mib-2.1.9.1.2.7 = OID: SNMPv2-SMI::mib-2.50
SNMPv2-SMI::mib-2.1.9.1.2.8 = OID: SNMPv2-SMI::snmpModules.16.2.2.1
SNMPv2-SMI::mib-2.1.9.1.3.1 = STRING: "The SNMP Management Architecture MIB."
SNMPv2-SMI::mib-2.1.9.1.3.2 = STRING: "The MIB for Message Processing and Dispatching."
SNMPv2-SMI::mib-2.1.9.1.3.3 = STRING: "The management information definitions for the SNMP User-based Security Model."
SNMPv2-SMI::mib-2.1.9.1.3.4 = STRING: "The MIB module for SNMPv2 entities"
SNMPv2-SMI::mib-2.1.9.1.3.5 = STRING: "The MIB module for managing TCP implementations"
SNMPv2-SMI::mib-2.1.9.1.3.6 = STRING: "The MIB module for managing IP and ICMP implementations"
SNMPv2-SMI::mib-2.1.9.1.3.7 = STRING: "The MIB module for managing UDP implementations"
SNMPv2-SMI::mib-2.1.9.1.3.8 = STRING: "View-based Access Control Model for SNMP."
SNMPv2-SMI::mib-2.1.9.1.4.1 = Timeticks: (37) 0:00:00.37
SNMPv2-SMI::mib-2.1.9.1.4.2 = Timeticks: (39) 0:00:00.39
SNMPv2-SMI::mib-2.1.9.1.4.3 = Timeticks: (41) 0:00:00.41
SNMPv2-SMI::mib-2.1.9.1.4.4 = Timeticks: (69) 0:00:00.69
SNMPv2-SMI::mib-2.1.9.1.4.5 = Timeticks: (69) 0:00:00.69
SNMPv2-SMI::mib-2.1.9.1.4.6 = Timeticks: (69) 0:00:00.69
SNMPv2-SMI::mib-2.1.9.1.4.7 = Timeticks: (70) 0:00:00.70
SNMPv2-SMI::mib-2.1.9.1.4.8 = Timeticks: (87) 0:00:00.87
SNMPv2-SMI::mib-2.25.1.1.0 = Timeticks: (558841) 1:33:08.41
SNMPv2-SMI::mib-2.25.1.2.0 = Hex-STRING: 07 DF 04 1A 0F 01 0E 00 2B 00 00 
SNMPv2-SMI::mib-2.25.1.3.0 = INTEGER: 1536
SNMPv2-SMI::mib-2.25.1.4.0 = STRING: "dma.dmachans=0x7f35 bcm2708_fb.fbwidth=1824 bcm2708_fb.fbheight=984 bcm2708.boardrev=0xf bcm2708.serial=0xe5a84b19 smsc95xx.maca"
SNMPv2-SMI::mib-2.25.1.5.0 = Gauge32: 3
SNMPv2-SMI::mib-2.25.1.6.0 = Gauge32: 82
SNMPv2-SMI::mib-2.25.1.7.0 = INTEGER: 0
End of MIB

Controlling the LEDs of a USB Keyboard connected to RaspberryPi using SNMP

I will show you how to read the LEDs’ status of a USB Keyboard connected to RaspberryPi and how to change the status of Scroll-Lock LED remotely (X11 libs don’t accept to control CapsLock and NumLock). We will use the SNMP protocol to read the LEDs status and write to Scroll-Lock LED.

Because I only found a 2GB SD Card here in my house I was forced to use the old “2012-10-28-wheezy-raspbian.img” Raspbian image to fit inside this card.

After installing and configuring Raspbian it returned “403 Forbidden Failed” when attempting to install packages.

You can fix it editing /etc/apt/source.list removing the default repository and adding:

deb http://archive.raspbian.org/raspbian wheezy main contrib non-free

Install all necessary software to get SNMP working and X11 lib to control keyboard LEDs:

$ sudo apt-get install snmp-mibs-downloader libsnmp-dev snmp snmpd libx11-dev

Verify the paths where “snmpd” are looking for snmpd.conf and for MIBs:

$ net-snmp-config --default-mibdirs

As you can see it returned many paths, but among them the /home/pi/.snmp. This is a place where snmpd will look to find a config file. We will put our file there.

First let create the .snmpd directory:

$ mkdir -p ~/.snmp/mibs/
$ mkdir -p ~/snmp/src/

Download the file exemplo.zip

Decompress it and copy EXEMPLO-MIB file to ~/.snmp/mibs:

$ cp snmp/EXEMPLO-MIB ~/.snmp/mibs

Edit the file /etc/snmp/snmp.conf and replace “mibs :” by:

mibs +EXEMPLO-MIB

Also copy exemplo.c and exemplo.h files to ~/snmp/src:

$ cp snmp/exemplo.* ~/snmp/src

Enter inside ~/snmp/src and create the shared library (AKA snmp module) :

$ cd ~/snmp/src
$ gcc `net-snmp-config --cflags` -fPIC -shared -g -O0 -o exemplo.so exemplo.c `net-snmp-config --libs` -lX11

Copy it to /usr/lib:

$ sudo cp exemplo.so /usr/lib
$ sudo ldconfig

We need to load this library using SNMP commands, but to use SNMP commands we need to create an User and Password.

To do it enter inside ~/.snmp and create a basic configuration (snmpd.conf) file there:

$ cd ~/.snmp
$ snmpconf -r none -g basic_setup

Do you want to configure the information returned in the system MIB group
(contact info, etc)? (default = y):y

The location of the system: your location

The contact information: your name

Do you want to properly set the value of the sysServices.0 OID
(if you don't know, just say no)? (default = y): n

Do you want to allow SNMPv3 read-write user based access (default = y):y

The SNMPv3 user that should have read-write access: raspi

The minimum security level required for that user
[noauth|auth|priv, default = auth]: auth

The OID that this community should be restricted to [if appropriate]: 

Finished Output: rwuser raspi auth
Do another rwuser line? (default = y):n

Do you want to allow SNMPv3 read-only user based access (default = y):y

Enter the SNMPv3 user that should have read-only access to the system: joe

The minimum security level required for that user [noauth|auth|priv, default = auth]: auth

The OID that this community should be restricted to [if appropriate]: .1.3.6.1.4.1.54321

Do another rouser line? (default = y): n

Do you want to allow SNMPv1/v2c read-write community access (default = y): y

Enter the community name to add read-write access for: acme

The hostname or network address to accept this community name from [RETURN for all]: 

The OID that this community should be restricted to [RETURN for no-restriction]: 

Do another rwcommunity line? (default = y): n

Do you want to allow SNMPv1/v2c read-only community access (default = y): n

Do you want to configure where and if the agent will send traps? (default = y): n

Do you want to configure the agent's ability to monitor varios aspects of your system (default = y): n

It will create the snmpd.conf file at our current location (/home/pi/.snmp/)

Stop snmpd and start it manually:

$ sudo service snmpd stop
$ sudo snmpd -f -L -Dexemplo,dlmod

If you faced some user/password issues at this point you can stop the snmp service and configure the /etc/snmp/snmp.conf this way:

mibs +EXEMPLO-MIB
defSecurityName raspi
defContext ""
defAuthType MD5
defSecurityLevel authNoPriv
defAuthPassphrase password
defVersion 3

You can replace “defAuthPassphrase password” by “defAuthPassphrase yourpass” but “yourpass” needs to have at least 8 characters.

Remember to start the snmpd server before execute next commands.

Now we can load the library, to do it create a new row in the dlmod table:

$ snmpset -c acme -v3 -u raspi -A password localhost UCD-DLMOD-MIB::dlmodStatus.1 i create 

UCD-DLMOD-MIB::dlmodStatus.1 = INTEGER: create(6)

We can see its content using this command:

$ snmptable -c acme -v3 -u raspi -A password localhost UCD-DLMOD-MIB::dlmodTable 

SNMP table: UCD-DLMOD-MIB::dlmodTable

 dlmodName dlmodPath dlmodError dlmodStatus
                                   unloaded

We need to update this new row with our dynamic module info:

$ snmpset -c acme -v3 -u raspi -A password localhost UCD-DLMOD-MIB::dlmodName.1 s "exemplo" UCD-DLMOD-MIB::dlmodPath.1 s "/usr/lib/exemplo.so"

MIB::dlmodName.1 = STRING: exemplo
UCD-DLMOD-MIB::dlmodPath.1 = STRING: /usr/lib/exemplo.so

Load the dynamic module:

$ snmpset -c acme -v3 -u raspi -A password localhost UCD-DLMOD-MIB::dlmodStatus.1 i load

UCD-DLMOD-MIB::dlmodStatus.1 = INTEGER: load(4)

Confirm it was loaded successfully:

$ snmptable -c acme -v3 -u raspi -A password localhost UCD-DLMOD-MIB::dlmodTable 

SNMP table: UCD-DLMOD-MIB::dlmodTable

 dlmodName           dlmodPath dlmodError dlmodStatus
   exemplo /usr/lib/exemplo.so                 loaded

You can test if it is working this way:

$ snmpget -c acme -v3 -u raspi -A password localhost EXEMPLO-MID::scrollLock.0

EXEMPLO-MIB::scrollLock.0 = INTEGER: 0

Now you can write to Scroll-Lock LED this way:

$ snmpset -c acme -v3 -u raspi -A password localhost EXEMPLO-MID::scrollLock.0 i 1

EXEMPLO-MIB::scrollLock.0 = INTEGER: aceso(1)

If everything worked fine the Scroll-Lock LED of keyboard connected to RaspiberryPi will turn on!

Now time to try the remote access! My Raspi board got the IP 192.168.0.15 and my computer got the IP 192.168.0.14. Then from my computer I tried to control the Scroll-Lock this way:

$ snmpset -c acme -v3 -u raspi -A password 192.168.0.15 EXEMPLO-MIB::scrollLock.0 i 1
snmpset: Timeout

Unfortunately it didn’t work! More some Internet search and I discovered that I need to use the interface IP in the snmpd command line to get it working:

$ sudo snmpd -f -L -Dexemplo,dlmod 192.168.0.15

Let me try again:

$ snmpset -c acme -v3 -u raspi -A password 192.168.0.15 EXEMPLO-MIB::scrollLock.0 i 1
Error in packet.
Reason: authorizationError (access denied to that object)

Now the error changed to authorization access.

Just more some search and I find out the right way to go:

$ snmpset -c acme -v3 -u raspi -A password -l authNoPriv 192.168.0.15 EXEMPLO-MIB::scrollLock.0 i 1
EXEMPLO-MIB::scrollLock.0 = INTEGER: aceso(1)

If you want to enable the SNMPv1 support in the snmpd you need to edit the /etc/snmp/snmpd.conf and add:

view         acmeonly      included    .1.3.6.1.4.1.54321
rwcommunity  acme          default     -V acmeonly

You can test if it worked this way:

$ snmpset -c acme -v1 192.168.0.15 EXEMPLO-MIB::scrollLock.0 i 1

EXEMPLO-MIB::scrollLock.0 = INTEGER: 1

All done!

Source for SNMP configuration: http://net-snmp.sourceforge.net/tutorial/tutorial-5/demon/snmpd.html

Creating a SNMP agent in the Debian

This post is a logic continuation of my friend Marcelo’s posts (in Portuguese sorry) :

https://jedizone.wordpress.com/2012/03/08/o-guia-definitivo-para-os-iniciantes-em-net-snmp-6/
https://jedizone.wordpress.com/2012/03/21/o-guia-definitivo-para-os-iniciantes-em-net-snmp/

When trying to run mib2c in Debian I got this error:

$ mib2c -c mib2c.scalar.conf exemplo

ERROR: You don't have the SNMP perl module installed.  Please obtain
this by getting the latest source release of the net-snmp toolkit from
http://www.net-snmp.org/download/ .  Once you download the source and
unpack it, the perl module is contained in the perl/SNMP directory.
See the README file there for instructions.

Then I downloaded the current netsnmp tarball, decompressed and executed:

$ cd net-snmp-5.7.3/perl/
$ perl Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for NetSNMP::default_store
Writing MYMETA.yml and MYMETA.json
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for NetSNMP::ASN
Writing MYMETA.yml and MYMETA.json
ERROR:
Net-SNMP installed version: 5.7.2.1 => 5.07021
Perl Module Version:        5.0703

These versions must match for perfect support of the module.  It is possible
that different versions may work together, but it is strongly recommended
that you make these two versions identical.  You can get the Net-SNMP
source code and the associated perl modules directly from 

   http://www.net-snmp.org/

If you want to continue anyway please set the NETSNMP_DONT_CHECK_VERSION
environmental variable to 1 and re-run the Makefile.PL script.

Hmm, after downloading the netsnmp version 5.7.2.1 (that is the version used by my Debian distro) and repeated the process and it worked fine:

$ cd net-snmp-5.7.3/perl/
$ perl Makefile.PL
$ make
$ sudo make install

Great perl snmp module compiled and installed.

Now we can create our MIBs as a dynamic library (called module in this context) :

$ mib2c -c mib2c.scalar.conf exemplo

$ gcc `net-snmp-config --cflags` -fPIC -shared -g -O0 -o exemplo.so exemplo.c `net-snmp-config --libs` -lX11

Copy it to your defaul library directory (optional, but recommend if you are a “copypaster”) :

$ sudo cp exemplo.so /usr/lib
$ sudo ldconfig

Edit/create file /etc/snmp/snmpd.conf with:

createUser initial
rwuser initial

You can replace “initial” by other user, but you need to create this new user using the “net-snmp-config” command. This “initial” is an initial user that comes pre-configured in the snmp.

Case snmpd is running you need to stop it:

$ sudo service snmpd stop

Now start snmpd manually and ask it to debug the modules exemplo,dlmod:

$ sudo snmpd -f -L -Dexemplo,dlmod

Unfortunately this is not enough to start your dynamic module, as you can see:

$ snmpget -c acme -v3 -u initial -l noAuthNoPriv localhost EXEMPLO-MIB::scrollLock.0

EXEMPLO-MIB::scrollLock.0 = No Such Object available on this agent at this OID

We need to create a new row in the dlmod table:

$ snmpset -c acme -v3 -u initial -l noAuthNoPriv localhost UCD-DLMOD-MIB::dlmodStatus.1 i create 

UCD-DLMOD-MIB::dlmodStatus.1 = INTEGER: create(6)

We can see its content using this command:

$ snmptable -c acme -v3 -u initial -l noAuthNoPriv localhost UCD-DLMOD-MIB::dlmodTable 

SNMP table: UCD-DLMOD-MIB::dlmodTable

 dlmodName dlmodPath dlmodError dlmodStatus
                                   unloaded

We need to update this new row with our dynamic module info:

$ snmpset -c acme -v3 -u initial -l noAuthNoPriv localhost UCD-DLMOD-MIB::dlmodName.1 s "exemplo" UCD-DLMOD-MIB::dlmodPath.1 s "/usr/lib/exemplo.so"

MIB::dlmodName.1 = STRING: exemplo
UCD-DLMOD-MIB::dlmodPath.1 = STRING: /usr/lib/exemplo.so

Load the dynamic module:

$ snmpset -c acme -v3 -u initial -l noAuthNoPriv localhost UCD-DLMOD-MIB::dlmodStatus.1 i load

UCD-DLMOD-MIB::dlmodStatus.1 = INTEGER: load(4)

Confirm it was loaded successfully:

$ snmptable -c acme -v3 -u initial -l noAuthNoPriv localhost UCD-DLMOD-MIB::dlmodTable 

SNMP table: UCD-DLMOD-MIB::dlmodTable

 dlmodName           dlmodPath dlmodError dlmodStatus
   exemplo /usr/lib/exemplo.so                 loaded

Now that the dynamic library was loaded you can repeat the above command:

$ snmpget -c acme -v3 -u initial -l noAuthNoPriv localhost EXEMPLO-MIB::scrollLock.0

EXEMPLO-MIB::scrollLock.0 = INTEGER: 0

Let try to set it to 1:

$ snmpset -c acme -v3 -u initial -l noAuthNoPriv localhost EXEMPLO-MIB::scrollLock.0 i 1

EXEMPLO-MIB::scrollLock.0 = INTEGER: aceso(1)

Let to double check it changed:

$ snmpget -c acme -v3 -u initial -l noAuthNoPriv localhost EXEMPLO-MIB::scrollLock.0

EXEMPLO-MIB::scrollLock.0 = INTEGER: aceso(1)

Source: http://net-snmp.sourceforge.net/tutorial/tutorial-5/toolkit/dlmod/

How to create SNMP User: https://stomp.colorado.edu/blog/blog/2010/07/09/on-configuring-snmpv3-in-net-snmp/

VSCP: Very Simple Control Protocol

I found about VSCP (www.vscp.org) in the Twitter and just start reading its specification and documentation.

VSCP is a control protocol developed by Åke Hedman since 2000, then it is about 15 years old! Many people are using it for home automation: http://www.vscp.org/wiki/doku.php/who_why_where/the_vscp_team.

The source code is released as GPL/LGPL but has some modified clauses that let users to use it in a “non-viral” mode. You just need to release the modifications you did (if you did it) in the VSCP code. This is similar to FreeRTOS GPL license in this sense.

It is a surprise to know that 8devices USB2CAN dongle has a VSCP driver:
http://www.8devices.com/usb2can

The 8Devices owner is a nice guy, even the USB2CAN schematic is released:
http://www.8devices.com/media/files/usb2can.pdf

Compiling Lintouch in the Debian Squeezy

This procedure was performed inside a VirtualBox machine running Debian Squeezy (installed from debian-6.0.10-amd64-netinst.iso) in a 64GB virtual disk.

First step: install all development packages:

$ sudo apt-get install \
build-essential \
automake \
libtool \
texinfo \
libncurses5-dev \
libusb-dev \
libxml2-dev \
libusb-1.0-0-dev \
cmake \
gawk \
gperf \
bison \
flex \
chrpath \
git \
gitk \
subversion \
vim \
doxygen \
libcppunit-dev \
libapr1-dev \
libaprutil1-dev \
libsnmp-dev \
libqt3-mt-dev \
libqwt-dev

Clone Lintouch repository:

$ git clone https://github.com/acassis/lintouch.git

### Initial Configuration/Compilation ###

$ cd lintouch/lintouch
$ ./bootstrap
$ ./configure
$ make
$ sudo make install

Now you can just call the Lintouch editor to start developing your project:

$ lintouch-editor