Unipolar Steppers con L298 y Arduino






Conexiones:

Stepper:

Blanco y negro: unirlos y no conectarlos a nada
Amarillo: MOTORA- (del L298)
Rojo: MOTORA+ (del L298)
Naranja: MOTORB- (del L298)
Azul: MOTORB+ (del L298)

ENA: Digital 2 de Arduino
IN1: Digital 3
IN2: Digital 4

ENB: Digital 5
IN3: Digital 6
IN4: Digital 7

VMS: Power del L298: 14v (pero puede ser hasta 35v)

Todas las GND juntas! como siempre!

Codigo arduino:


#include <Stepper.h>
const int stepsPerRevolution = 200;

Stepper myStepper(stepsPerRevolution, 3,4,6,7);          
void setup() {
   myStepper.setSpeed(150);
   int ENA=2;//connected to Arduino's port 2
   int ENB=5;//connected to Arduino's port 5
 
   digitalWrite(ENA,HIGH);//enablae motorA
   digitalWrite(ENB,HIGH);//enable motorB
}
void loop() {
  //horario
  myStepper.step(stepsPerRevolution);
  delay(500);

  // antihorario
  myStepper.step(-stepsPerRevolution);
  delay(500);
}







Cambiar la vista de todas las carpetas en windows

Para cambiar la vista predeterminada en todas las carpetas de windows (por ejemplo, para agregar la columna Descripcion)

1. Abrir la carpeta (ej, c:\windows\microsoft.net\assembly)

2. Sobre cualquier columna, click derecho / Mas... / y elegir la columna (por ejemplo, Descripcion del archivo)

3. Apretar "Alt", luego Herramientas / Opciones de carpeta

4. En la ficha Ver, presionar "Aplicar a las carpetas"

int b=2;

void main()
{
   int j=2;
   j++;
   i++;
}

Habilitar debug remoto en aplicaciones .NET

Requisitos:

1. Los fuentes locales deben corresponderse con los binarios que estén en el servidor remoto (para asegurarse, publicar nuevamente)

Pasos:

1. Instalar rtools_setup_x64 en el servidor remoto


2. Iniciar el remote debugger en el servidor remoto (Inicio / Remote Debugger)

*** Si no deja abrir el remote debugger (porque dice que ya esta corriendo) hay que matar el proceso msvsmon y ejecutar de nuevo inicio/remote debugger ***

Hay que agregar a userconnect (igual a como esta en esta imagen)


3. Agregar algun breakpoint en el fuente local

4. Ir a Tools/Attach to Process

5. Ingresar el nombre del servidor remoto (el que tiene el Remote Debugger corriendo)



6. Marcar "Show processes from all users"

7. Para identificar a cual w3wp debemos hacer el attach:

         En el servidor remoto, abrir un cmd como administrador
         cd C:\Windows\System32\inetsrv
         appcmd.exe list wp

Aparece una lista de los procesos correspondientes a los app. pool que están ejecutandose:


En este caso, queremos hacer debug de Cobranza, por lo tanto, el proceso es 8628

*** Si no aparece el proceso, es porque el mismo se crea sólamente luego del primer acceso, por lo cual hay que abrir un browser y abrir el sitio, y luego de eso se va a poder ver el worker process ***

8. Volver al visual studio local, ir a Tools / Attach to Process, marcar "Show processes from all users" y seleccionar el proceso 8628, y presionar "Attach"


9. Abrir un browser, y acceder al sitio.





PAN3401 y PAN3101 - A2636 pinout








Pinout con arduino:

PIN 7 - SCLK    a digital 2 de Arduino
PIN 8 - SDIO    a digital 3 de arduino
PIN 4 - GND     a GND de arduino
PIN 5 - VCC     a VCC de arduino


Codigo:

// This example reads out the PixArt PAN3101 Optical Navigation Sensor
// It's used in many cheap optical mouses.
//
// For support for the Agilent ADNS-2051, ADNS-2083 or ADNS-2610, move
// the files for your mouse to the folder with the OptiMouse files.
// Then uncomment the right header files and object instances below.
//
// The Arduino will keep track of a (x, y) coordinate by increasing
// or decreasing the x and y variables by dx and respectively dy.
// Every 128th sample it reports the current (x, y) over the Serial.
//
// Written by Martijn The -> post [at] martijnthe.nl
// Tutorial: http://www.martijnthe.nl/optimouse/
// Based on the sketches by Beno�t Rousseau

#include "PAN3101.h"
// #include "ADNS2051.h"
// #include "ADNS2610.h"
// #include "ADNS2083.h"

#define SCLK 2                            // Serial clock pin on the Arduino
#define SDIO 3                            // Serial data (I/O) pin on the Arduino

PAN3101 Optical1 = PAN3101(SCLK, SDIO);   // Create an instance of the PAN3101 object
// ADNS2051 Optical1 = ADNS2051(SCLK, SDIO);
// ADNS2610 Optical1 = ADNS2610(SCLK, SDIO);
// ADNS2083 Optical1 = ADNS2083(SCLK, SDIO);

signed long x = 0;                        // Variables for our 'cursor'
signed long y = 0;                        //

int c = 0;                                // Counter variable for coordinate reporting

void setup()
{
  Serial.begin(38400);
  Optical1.begin();                       // Resync (not really necessary?)
}

void loop()
{

//  The status commands are available only for the PAN3101 and the ADNS2051:

//  Optical1.updateStatus();                // Get the latest motion status
//  if (Optical1.motion())                  // If the 'Motion' status bit is set,
//  {

    x += Optical1.dx();                   // Read the dX register and in/decrease X with that value
    y += Optical1.dy();                   // Same thing for dY register.....

//  }
 
  if (c++ & 0x80)
  {                                       // Report the coordinates once in a while...
    Serial.print("x=");
    Serial.print(x, DEC);
    Serial.print(" y=");
    Serial.print(y, DEC);
    Serial.println();
    c = 0;                                // Reset the report counter
  }
}


Referencias a dll de assembly en vistas de razor

Si se quiere utilizar una dll del GAC desde una vista razor, es necesario agregarlo como referencia en el Web.config que está dentro de la carpeta Views.

Por ejemplo, si se utiliza en una vista lo siguiente:

@using Sistema.Configuracion.Util

Es necesario agregar en el web.config que está dentro de  Views, lo siguiente:

  <system.web.webPages.razor>
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="Sistema.Configuracion.Util" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>


<system.web>
    ...
    ...
    <compilation debug="true" targetFramework="4.5.1">
      <assemblies>
                <add assembly="Sistema.Configuracion.Util, Version=1.0.0.0, Culture=neutral, PublicKeyToken=62a692e0bdb17eee" />
      </assemblies>
    </compilation>
    ...
    ...
</system.web>


RECORDAR DEJAR EN FALSE LA PROPIEDAD COPY LOCAL DE LA REFERENCIA (EN REFERENCES)

Instalar remotamente en assembly de otro equipo

Utilizar psexec:

copy dll1.dll \\Xdesa\temp

psexec \\nombre-del-servidor "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\x64\gacutil" /i c:\temp\dll1.dll /f


Instalar dll en GAC automaticamente luego de hacer build en Visual Studio

http://abhijitjana.net/2011/08/25/install-a-shared-assembly-to-the-gac-as-post-build-event-from-visual-studio/

En las propiedades del proyecto, en Build Events, agregar en Post-build event command line:

call "$(DevEnvDir)..\Tools\vsvars32.bat"
"%ProgramFiles(x86)%\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe" /i "$(TargetPath)" /f

Recordar que las dlls deben estar firmadas para poder ser publicadas en GAC

Si el gacutil no esta disponible, hay que instalar los SDK 8.1 de Windows:







Leer mouse ps2 o USB con arduino y enviar datos a C#

*** Libreria PS2 en DRIVE ***

Para mouse con conector PS2

pin 5 (CLOCK) -> Arduino digital 6
pin 1 (DATA)   -> Arduino digital 5
pin 4 (VCC)      -> Arduino VCC
pin 3 (GND)      -> Arduino GND

Codigo Arduino:

#include <ps2.h>

PS2 mouse(6, 5);

void mouse_init()
{
  mouse.write(0xff);  // reset
  mouse.read();  // ack byte
  mouse.read();  // blank */
  mouse.read();  // blank */
  mouse.write(0xf0);  // remote mode
  mouse.read();  // ack
  delayMicroseconds(100);
}

void setup()
{
  Serial.begin(9600);
  mouse_init();
}

void loop()
{
  char mstat;
  int mx;
  int my;

  mouse.write(0xeb);  // give me data!
  mouse.read();      // ignore ack
  mstat = mouse.read();
  mx = mouse.read();
  my = mouse.read();

  if (mx != 0)
  {
    if (mx > 200)
      Serial.println("L");
    if (mx < 200)
      Serial.println("R");
  }

  if (my != 0)
  {
    if (my > 200)
    {
      Serial.println("D");
    }
    if (my < 200)
      Serial.println("U");
  }
}


Codigo C#

*** Agregar un timer con intervalo 1 ***

using System;
using System.IO.Ports;
using System.Windows.Forms;

namespace Mouse3
{
public partial class MainForm : Form
{
SerialPort port = null;
bool U, D, L, R = false;
static int inc = 10;

public MainForm()
{
InitializeComponent();
}

void MainFormLoad(object sender, EventArgs e)
{
string[] ports = SerialPort.GetPortNames();

foreach (string p in ports)
{
   port = new SerialPort(p, 9600);
   if (port.PortName == "COM15")  
break;
}

port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived);
port.Open();
}

  void port_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
  int n = 0;
  int count = port.BytesToRead;
while (count > 0)
{
   n = port.ReadByte();
 
   var letra = Convert.ToChar(n);
 
   switch (letra)
   {
    case 'U': U = true; break;
case 'D': D = true; break;
case 'L': L = true; break;
case 'R': R = true; break;
   }

   count--;
}

        }
 
void Timer1Tick(object sender, EventArgs e)
{
if (U)
{
pic1.Top-=inc;
U = false;
}
if (D)
{
pic1.Top+=inc;
D = false;
}
if (L)
{
pic1.Left-=inc;
L = false;
}
if (R)
{
pic1.Left+=inc;
R = false;
}
}
}
}




Para mouse con conector USB


Verde (CLOCK)  -> Arduino digital 6
Blanco (DATA)   -> Arduino digital 5
Rojo (VCC)          -> Arduino VCC
Negro (GND)       -> Arduino GND

El codigo para arduino es el mismo.


-------------------------------------------------------------------------------------------------------------


Fuentes:
http://playground.arduino.cc/ComponentLib/Ps2mouse


http://sohilpatel.org/arduino-ps2-mouse/


PARA MOUSE USB:
http://www.msx.org/forum/msx-talk/hardware/use-10eu-connect-modern-mouse-msx




My bluetooth


Bluetooth con Attiny85

Fuente: http://arduinofy.blogspot.com/2013/05/attiny-bluetooth.html


Tuorial: Attiny84 / 85 and Bluetooth 

Tuorial: Attiny84 / 85 and Bluetooth

What This Tutorial Covers

This tutorial is an expansion / continuation of the previous Bluetooth tutorial. In other words I will assume you are familiar with arduino and simple Bluetooth concepts. Also, I assume you know how to program an Attiny via arduino as an ISP or via a standalone programmer. I'm not going to be going over the code in detail unless it is something I didn't cover in the previous tutorial.

In this tutorial we will learn how to connect a Bluetooth module to an Attiny and how to make them talk! Exciting isint it? This will allow you to control a shrinkified arduino project wirelessly via Bluetooth from another arduino bluetooth enabled device, via a computer or even via a phone. In this tutorial I will cover how to control your Bluetooth enabled Attiny via a computer, but soon I will be doing a tutorial on how to accomplish this via an iPhone.


What You Need

For this tutorial you will need a few things, here is the list:
- Attiny84 or 85
- Bluetooth module
- a bread board and some wires

Identify your Bluetooth

The first thing you have to do is check your hardware and find out which pin means what. This is not difficult and either the manufacturer or the retailer which you have purchased the module from should provide you with a schematic. Here is the module I'm using the HC-05 Bluetooth Transceiver:


You can get it from here from NYPLATFORM on ebay. ($11)

Set Up

Here are two pictures of the setup:




I know its not clear so I will run through it in more detail in text. The Bluetooth module I'am using has 6 pins. I'm using only 4 of them. The TX, RX, 5V, and GROUND. This is all you need to run the Bluetooth and make it work. Some other features are excluded due to this but I will leave it up to you to discover them.

OK, first the simple stuff that you should be familiar with already. In the code notice that I initiate "int led = 4" pin 4 as "led", then I set it up for output and turn it on. We will be using this led to verify connection with our computer via Putty. In other words we will control the led via Bluetooth and make it turn on and off. As mentioned before this led is connected to Attiny pin 4, in my setup I'm using a resistor (should be 330ohm) between the Attiny and the led as I do not want to fry the led.

Now for connecting the Bluetooth with the Attiny. This is simpler that you would have ever thought, all you need is two wires or jumpers that connect the RX pin with pin 1 on the Attiny and connect the TX pn with pin 2 on the Attiny. Now make sure everything has 5V connected to it, the Bluetooth module and the Attiny.

NOTE: some Bluetooth modules could be using a different Voltage!!!

Programming

Hold on there! Before we start programming there is one thing you have to make sure of. In order for this to work properly as I found out you have to burn the 8mhz boot loader for the Attiny! Google is your friend on this one.

Now, since I have gone through most of the code in my previous tutorial I will not be detailed on this. The only part that I will make remarks about is the new code that controls the led.

/*
This code will run the bluetooth as slave
pressing 1 turns on led 4
pressing 0 turns off led 4
*/
 
#include    //Software Serial Port
#define RxD 1
#define TxD 2

#define DEBUG_ENABLED  1
 
SoftwareSerial blueToothSerial(RxD,TxD);

int led = 4;
 
void setup() 
{ 
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  setupBlueToothConnection();
  
  pinMode(led,OUTPUT);
  digitalWrite(led,HIGH);
 
} 
 
void loop() 
{ 
  char recvChar;
  while(1){
    //check if there's any data sent from the remote bluetooth shield
    if(blueToothSerial.available()){
      recvChar = blueToothSerial.read();
      
        if(recvChar == '1')
          digitalWrite(led,HIGH);  
       
        else
          digitalWrite(led,LOW); 
    }
  }
} 
 
void setupBlueToothConnection()
{
  blueToothSerial.begin(9600); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=HC-05\r\n"); //set the bluetooth name as "HC-05"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  
  delay(2000); // This delay is required.
  //blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  blueToothSerial.print("bluetooth connected!\n");
  
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}

The only new code that you should see is the following:
void loop() 
{ 
  char recvChar;
  while(1){
    //check if there's any data sent from the remote bluetooth shield
    if(blueToothSerial.available()){
      recvChar = blueToothSerial.read();
      
        if(recvChar == '1')
          digitalWrite(led,HIGH);  
       
        else
          digitalWrite(led,LOW); 
    }
  }
} 

This is our loop. We do this 8mhz per second. Lets take a look at it and what it does. It is not very complicated and just looking at it you should be able to figure it out. Skipping to the first if statement, we are checking if there is any data that has been transmitted from the master device. Then, if there was we write it into a char. Now the char should be holding whatever value you have passed to it. In this example I choose "1" and any. "1" will turn on the led and any other will turn it off. Now in the second if statement we are comparing the char to "1" and if they match then we turn the led on. If they don't match we turn it off. So, as long as the connection is working, you should be able to turn off the led that is turned on at initialization.

Getting it All Connected

Now, power everything on. If you are using the same module as I am, you should see a red blinking led. This is good, your Bluetooth device is ready for pairing. Open up your computers Bluetooth software, find HC-05 and connect to it. This device uses a 4 digit pairing code. The default is "1234", type it in and sync them together. Open up device manager in control panel note the COM port that the Bluetooth is using, if there is more than one you will have to try them all if your unlucky. Open up putty select COM connection type in the COM# and leave the bound rate at 9600, this is what we used in the code and this is what worked best for this device.
If putty opens up a new session (black window) with the text displaying "Bluetooth Connected" you are in business. Press any key and the led should turn off, press "1" and the led should turn on. Congratulations!! You have established a bluetooth connection using an Attiny.

Comments and Questions welcome!
Thanks for reading.

Libreria Flash no funciona con Arduino 1.6.0

Para que la libreria Flash funcione con la version 1.6.0 de Arduino, agregar las siguientes lineas al archivo Flash.h

#if ARDUINO >= 150
typedef char prog_char __attribute__((__progmem__));
#endif

*** si no permite editar el Flash.h, abrir el notepad como administrador y luego abrir el archivo ***