Posts Tagged ‘c#’
09
lug

A very easy project this morning!

A robotic – automatic notifier for google plus with an arduino, a servo motor and an… icecream box! (plus.google.com)!


arduino google plus notifier

How it works?
A c# tool call and parse this url: https://plus.google.com/u/0/_/n/guc, that returns, as response, a txt file called response.txt that contains these informations:

)]}’ ["on.uc",2,300,"101932929612066440630"]

after “on.uc” we can see number 2. The number of notifications!
Google notification url was found reading html page of google+ login. “On Success“, open url. To show you if there are any notifications.

The tool send on serial port a value only if > 0.

Arduino recognize the string and move the servo +/- 90°. The box will open (showing google logo) or close (hiding all)!

Arduino code:

1
2
  servo.write(0);
  if (val > 0) servo.write(90);


arduino google plus notifier

Very easy to do, 30m of work, but so coool!!!

Making of photos and video (today, only a simulated video because google plus and notification are under test):

arduino google plus notifier
arduino google plus notifier
arduino google plus notifier
arduino google plus notifier
arduino google plus notifier
arduino google plus notifier
arduino google plus notifier

yeeeees!

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , ,

11
giu

A test with servo and wifi/serial communication.

It’s a C#.net utility that send data over serial port or over wifi and move a servo connected to arduino.


arduino remote servo

Here the demo:



Here automatic version beta:



Totally auto version 1.0:




FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , , , ,

26
mag

I prefer to use the Visual Studio 2008 environment to write and test code for the Arduino. The following steps outline what is necessary to accomplish this.

Note that this requires two files to be added that are stub’s for the normal Arduino functions. The stubs provided here use defines for the Arduino Mega and create a simple console application that will map console input/output to the Arduino serial input/output.

For those of you who have more time at hand, it would be nice to write a windows stub which will also allow to see / control the I/O pins.

If you need support for other boards you need to edit the VSPDE.h file.

Also the VSPDE.cpp file does not implement all the Arduino functions, so if you need more, please feel free to update the code.

Main objective for me was to be able to edit and compile, and in a limited way run and debug code using Visual Studio. This will do just that (and nothing more)!

Step 1: Ensure .pde files are seen as C++ files

Open regedit and under \HKEY_CLASSES_ROOT create a new key called “.pde” and change the default value to “cppfile”.

   [HKEY_CLASSES_ROOT\.pde]
   @="cppfile"

Step 2: Configure Visual Studio

  1. Under tools \ options \ Projects and Solutions\VC++ Project settings add ‘*.pde’ to ‘C/C++ File Extensions’ and ‘.pde’ to the ‘Extensions to Include’
  2. Under tools\options\Text Editor\File Extension add PDE and map it to the C++ editor
  3. Close Visual Studio to effect the changes

Step 3: Create a Visual Studio project

  1. Start by creating a new (empty) sketch using the Arduino editor
  2. Next create a Visual C++ ‘Empty Project’ for the sketch in the same folder
  3. In the solution, right click and select Add, Existing item to add the .PDE file(s)
  4. Select the .PDE files, right click and in the file properties set the file type to ‘C/C++ Code’
  5. Add the VSPDE.h and VSPDE.cpp files
  6. Add an #include statement for the VSPDE.h file in the .pde files.
  7. You can now edit, compile and run the program as a console application (without I/O support!)

Step 4: Configure Arduino

Under File\Preferences set the ‘Use external editor’ checkmark.
Now you can use Visual studio to edit and when done just Alt-Tab to the Arduino application and press the upload button to compile the latest code and upload it to the board. The Arduino program will automatically monitor for file changes so you do not need to refresh anything!

Rif: www.arduino.cc




FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , ,

07
mag

Hi all!!
Today i show how is possible to connect iPhone to Arduino without any Wifi or Ethernet shields!

Here the app that controls 4 leds (green yellow, red and orange), a DC motor with a fan, a piezo speacker and the room temperature with LM32 sensor!


Arduino iphone control


What you need?
Arduino with anything you want
iPhone / iPad / iPod
– A website to host php pages
– An internet connection on pc (Win + Mac)

What you need to know?
– A little bit of electronics
C language
C# language
PHP language
Objective-C language

Good.
In PHP make a stupid page that get in $_REQUEST a command and store it to a file on server!
Three lines of code…

In C# make a web listener that call php page and checks the output. If any condition are verified, send to COM9 the value that you want to get from arduino.

In C from Arduino, in the Loop() read Serial value. If the value respond to your configuration, call LigthUpLed(green) for example!

In Objective-C make an iPhone App with a stupid layout that call in GET your PHP page and send a command!

To make everithink work, run your C# listener app on Windows and from your iPhone send get call to web server!

Now, your nerd app will control arduino!!!

In this example app that i made, i control HIGH or LOW for Four LEDs, a DC Motor, a Piezo Speacker and a Temperature Sensor.

I used resistors, 4 leds, LM32, DC Motor, TIP120, diode, wires, beer.




Here a screenshot (click to enlarge):


Arduino iphone control

Here a video:



Rif: albertopasca.it

enjoy!

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , ,

26
mar

Hi all,
as my first experiment, an arduino connected to COM9 to recognize incoming mails from google mail (gmail)!!
Very easy to do!!!





As experiment I connected Arduino board to a breadboard with a GREEN LED and a PIEZO SPEACKER in this way:


Arduino Gmail Notifier

Rif: albertopasca.it

I connected the LED to Arduino pin 13 and speacker to arduino pin 12.

The code sended to Arduino ATMEGA328 chip was this:
-It was programmed to read serial port data (sended from server by C# app)-

Arduino CODE (C):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* green led*/
const int ledPin = 13;

/* piezo */
const int beepPin = 12;

/* check gmail mails :D */
int mail = LOW;
int val;

void setup()
{
  /* setup pin iniziale */
  pinMode(ledPin, OUTPUT);      
  pinMode(beepPin, OUTPUT);
 
  Serial.begin(9600);
 
  mail = HIGH;
}

void loop()
{
  /* loop gmail check mails */
  val = Serial.read();
  Serial.println(val, BYTE);

  if (val == 110) { // "n" = 110 in dec from ascii
    mail = HIGH;
  } else if (val == 109) { //109 = "m" in dec from ascii
    mail = LOW;

    /* accendo il led*/
    digitalWrite(ledPin, HIGH);

    /* fischio avviso mail
        tipo fischio di fine
        partita di calcio */

    digitalWrite(beepPin, HIGH);
    delay(500);
    digitalWrite(beepPin, LOW);
    delay(200);
    digitalWrite(beepPin, HIGH);
    delay(500);
    digitalWrite(beepPin, LOW);
    delay(200);
    digitalWrite(beepPin, HIGH);
    delay(3000);

    /* rimetto tutto a posto */
    digitalWrite(beepPin, LOW);
    digitalWrite(ledPin, LOW);
  }  
}

After that Arduino code was uploaded to chip and programmed successfully, I make a C# app that loop on “while true” to check google mails every 10 seconds.
If there is a new incoming mail, it send to serial port (COM9, 9600) a char, “m” for new mail and “n” for NO mail that are interpreted from arduino respectly to 109 and 110 in DEC format.
Arduino CODE recognize the DEC (ascii code, m||n) and executed code relatively condition.
If there was a “m” code, it send an HIGH signal (1) to GREEN LED and an HIGH to speacker (temporized).
Until you don’t read your message, it beeps every 10 seconds!!




To do all of this tricks, you need to create a C# Windows || Console app and run on COM9 listening arduino.

This is C# code (VS2010 – C#4.0):

/* SEND / READ SERIAL PORT COM9 DATA */

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
try {
  SerialPort port = new SerialPort( "COM9", 9600, Parity.None, 8, StopBits.One );
  port.Open();

  string Unreadz = "0";
  while ( true ) {
    Unreadz = CheckMail();
    Console.WriteLine( "Unread Mails: " + Unreadz );

    if ( !Unreadz.Equals( "0" ) ) port.Write( "m" );
    else port.Write( "n" );

    Thread.Sleep( 10000 );
  }
} catch ( Exception ee ) { Console.WriteLine( ee.Message ); }

This ones check mails:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
private string CheckMail() {
    string result = "0";

    try {
      var url = @"https://gmail.google.com/gmail/feed/atom";
      var USER = "your.user.name";
      var PASS = "youRp@ssw0rd";

      var encoded = TextToBase64( USER + ":" + PASS );

      var myWebRequest = HttpWebRequest.Create( url );
      myWebRequest.Method = "POST";
      myWebRequest.ContentLength = 0;
      myWebRequest.Headers.Add( "Authorization", "Basic " + encoded );

      var response = myWebRequest.GetResponse();
      var stream = response.GetResponseStream();

      XmlReader reader = XmlReader.Create( stream );
      while ( reader.Read() )
        if ( reader.NodeType == XmlNodeType.Element )
          if ( reader.Name == "fullcount" ) {
            result = reader.ReadElementContentAsString();
            return result;
          }
    } catch ( Exception ee ) { Console.WriteLine( ee.Message ); }
    return result;
  }
}

…and last one, text convertion:

1
2
3
4
5
public static string TextToBase64( string sAscii ) {
  System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
  byte[] bytes = encoding.GetBytes( sAscii );
  return System.Convert.ToBase64String( bytes, 0, bytes.Length );
}

Now, upload code to arduino, press PLAY to C# project… and send you a mail to your gmail address!!!

enjoy beeping!

Rif: albertopasca.it





FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , , , , , , ,

25
mar

Hi all,
this is the first post about Arduino!

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It’s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.


Arduino Uno

www.arduino.cc

It’s learning time… stay tuned for Videos and Tutorials!!






Rif: albertopasca.it

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , , , , , ,

14
nov

This is my first post about Windows Phone 7 SDK!

It’s a C# snipplet to make call from your phone using PhoneCallTask!

1
2
3
4
PhoneCallTask pct = new PhoneCallTask();
pct.DisplayName = "Alberto Pasca";
pct.PhoneNumber = "+39328111111";
pct.Show();


Windows Phone 7 Make Call

stay tuned!





FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , ,

17
ott

Bene,
come al solito Microsoft non si tira indietro e presenta il nuovo SDK per Windows Phone 7 e XBOX 360!

Provato subito in anteprima!

Si presenta così il nuovo emulatore Microsoft. Un interfaccia completamente diversa dai soliti copia/incolla (Android, iPhone, Symbian) esistenti.

Windows Phone 7
Windows Phone 7




Ovviamente è stata creata subito la prima APP inutile, ma funzionante!

Windows Phone 7

Funzionamento dell’sdk abbastanza semplice.
Integrato in Visual Studio 2010, contiene i classici elementi da trascinare, proprietà, debug e via dicendo.
Usa XAML e C#.

La licenza per lo sviluppatore costa 99€ ed è valida un anno.

Rif: albertopasca.it

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , , , , ,

21
lug

Well,

a usefully thing (for me) that convert real media files like CAMV, RM, SMIL in iPod compatible video (AVI mpeg4).

It’s a multithread windows executable easy to use.

It merge RM and CAMV in AVI file and after convert the AVI in Mpeg4 for iPod compatible video in 320×240.

Rcam

you can download it here.

    - Requires Framework .net 2.0+. It’s a C# application.
    - Unzip all and click Rcam.exe. Mantain mencoder.exe and ffmpeg.exe in the same path of your executable.

If you prefer unix version of rm camv converter, read this old article.

WARNING! It’s a beta version 000000.000001 ! There are a lot of bugs… but it works!

it’s all.

Rif: albertopasca.it

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , , , , , , , , , , , ,

13
lug

Yes!
It’s double right click!

In this snippet you can use right double click to “go back” on your web browser!
It’s a stupid tricks, but it’s very useful!

Here we go!

As usually, copy and paste this snippet in your windows application.

First of all, you must include this libs:

using System.Runtime.InteropServices;
using System.Diagnostics;





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
private static LowLevelMouseProc _proc = HookCallback;
private static IntPtr _hookID = IntPtr.Zero;
private static MSLLHOOKSTRUCT _posDblClk;

private const int WH_MOUSE_LL = 14;

private enum MouseMessages
{
  WM_LBUTTONDOWN = 0x0201,
  WM_LBUTTONUP = 0x0202,
  WM_MOUSEMOVE = 0x0200,
  WM_MOUSEWHEEL = 0x020A,
  WM_RBUTTONDOWN = 0x0204,
  WM_RBUTTONUP = 0x0205
}

[StructLayout( LayoutKind.Sequential )]
private struct POINT
{
  public int x;
  public int y;
}

[StructLayout( LayoutKind.Sequential )]
private struct MSLLHOOKSTRUCT
{
  public POINT pt;
  public uint mouseData;
  public uint flags;
  public uint time;
  public IntPtr dwExtraInfo;
}

[DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
private static extern IntPtr SetWindowsHookEx( int idHook, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId );

[DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
[return: MarshalAs( UnmanagedType.Bool )]
private static extern bool UnhookWindowsHookEx( IntPtr hhk );

[DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = true )]
private static extern IntPtr CallNextHookEx( IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam );

[DllImport( "kernel32.dll", CharSet = CharSet.Auto, SetLastError = true )]
private static extern IntPtr GetModuleHandle( string lpModuleName );

Ok, this is first part of code, used to catch mouse event with windows API like kernel32.dll and user32.dll.

After that, create two simple method that invoke mouse hook:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
private static IntPtr SetHook( LowLevelMouseProc proc )
{
  using ( Process curProcess = Process.GetCurrentProcess() )
  using ( ProcessModule curModule = curProcess.MainModule ) {
    return SetWindowsHookEx( WH_MOUSE_LL, proc, GetModuleHandle( curModule.ModuleName ), 0 );
  }
}

private delegate IntPtr LowLevelMouseProc( int nCode, IntPtr wParam, IntPtr lParam );

private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam )
{
  if ( nCode >= 0 && MouseMessages.WM_RBUTTONDOWN == ( MouseMessages )wParam ) {
    MSLLHOOKSTRUCT hookStruct = ( MSLLHOOKSTRUCT )Marshal.PtrToStructure( lParam, typeof( MSLLHOOKSTRUCT ) );

    if ( ( _posDblClk.pt.x == hookStruct.pt.x ) && ( _posDblClk.pt.y == hookStruct.pt.y ) ) {
      SendKeys.Send( "%{LEFT}" );
    }
    _posDblClk.pt.x = hookStruct.pt.x;
    _posDblClk.pt.y = hookStruct.pt.y;
  }

  return CallNextHookEx( _hookID, nCode, wParam, lParam );
}

…you can view that in HookCallback function there is a method that use “%{LEFT}”, this is equivalent to ALT+LEFTARROW, used to go back in web browser.

SendKeys.Send( “%{LEFT}” );

When is detected a double right click, the program send to the system the ALT+LEFTARROW keys. If you are in a browser, you go back!

Finally,
in you form init, insert this lines

1
2
3
_hookID = SetHook( _proc );
Application.Run();
UnhookWindowsHookEx( _hookID );

that starting the mouse hook.

Perfect! Compile and test it!

If you like this tricks, add it in Windows Autorun!
If you like this post, click iLike!
If you don’t want to compile and want only to use it, you can download from here.




byz

Rif: albertopasca.it

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , , , , , , , , ,

Switch to our mobile site