Tuesday, November 23, 2010

Using Joysticks from VB.NET

There are several ways for using joystick on VB.NET: APIs and DirectX. Here I'll show you the DirectX Method.

First, download DirectX SDK from Microsoft:
http://msdn.microsoft.com/en-us/directx/aa937788.aspx
and then install it.

Starts a new project on VB.NET and add a reference to DirectX:
Project -> Add reference.
Select Microsoft.DirectX.DirectInput from list in ".NET" tab:


First thing to do is obtain a device list, but VB.NET will throw an exception (Loader Lock). Deactivate Loader Lock exception from menu Debud -> Exceptions. Explode "Managed Debugging Assistant", find "Loader Lock" and uncheck the box "Generated":



Imports DirectInput name space at top of your program:


Add a timer (timer1) on your form and set "Enabled" property on true (we'll use it for joystick polling).

Add a textbox named txtDir
Add a textbox named txtButtons

The code is the following:

Imports Microsoft.DirectX.DirectInput

Public Class Form1

    Dim joystickDevice As Device

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' List of attached joysticks
        Dim gameControllerList As DeviceList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)

        ' There is one controller at least?
        If (gameControllerList.Count > 0) Then

            ' Select first joystick
            gameControllerList.MoveNext()
            ' Create an object instance
            Dim deviceInstance As DeviceInstance = gameControllerList.Current

            joystickDevice = New Device(deviceInstance.InstanceGuid)
            joystickDevice.SetCooperativeLevel(Me, CooperativeLevelFlags.Background Or CooperativeLevelFlags.NonExclusive)

        End If

        joystickDevice.SetDataFormat(DeviceDataFormat.Joystick)
        joystickDevice.Acquire()

        Timer1.Start()
        

    End Sub

    Private Sub joystickPolling()

        Try
            joystickDevice.Poll()
            Dim state As JoystickState = joystickDevice.CurrentJoystickState

            txtDir.Text = "X=" & state.X & " Y=" & state.Y & " Z=" & state.Z

            txtbuttons.Text = state.GetButtons(0) & " " & state.GetButtons(1)

        Catch ex As Exception

        End Try
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        joystickPolling()

    End Sub
End Class

state object will contain all informations you need. State.X is the X position of joystick (type state followed by dot and see the entire list of controls).

the GetButtons property of state object will give you the state of buttons. GetButtons give an array. 
Example: 

dim button1 as byte = state.GetButtons(0) ' retrieve first button state

if the value is 128, the button is pressed, if the value is 0 the button isn't pressed or doesn't exists 

Monday, November 8, 2010

Modem Siemens TC35 - Ignition

The modems Siemens TC35, TC35i, TC37 are mainly used for deliver/receive sms in embedded systems. Those modems requires a start sequence to power up. Let's take a look to datasheet:


VBatt+ is the main voltage on TC35 (on TC35i this is called only Batt+), located on pins 1-5 of the module. VDDLP is a secondary power source used for RTCC backup, located on pin 30. IGT is the ignition line, used to turn on the module, pin 15.

As you see from the diagrams, the module will no power up with only with VBatt+, but it needs a signal on IGT pin for at least 100mS at low level when you power up the main line. After the 100mS at low level, IGT line must go to High Impedance, but I've tried with a circuit that goes to high level instead High impedance without any damage (please try it at your own risk!).

The schematic is the following (thanks to P. Seminara of robotics-net.com):


WARNING! This schematic is only usable with a TC35 mounted on an adapter board that translates logic levels (5V <-> 3V)

When you power up the circuit (+5V), C1 will let pass some current (until it's fully charged). This current, through R1 will take T1 to saturation, closing collector with emitter and then on IGT line there is 0V. When C1 is fully charged (after about 150mS, RC constant of this circuit is of 147mS), T1 will be interdicted because C1 will stop the current flow and then the base of T1 will tied down by R2. 

Actually, T1 will be interdicted when Vbe falls under 0.7V

In this condition the circuit betwewn collector and emitter will open and the IGT goes to high level thanks R3 (pullup resistor).

On the oscilloscope we'll observe this behaviour:


The Cyan line is the main power, yellow is the IGniTion line. After power-up, the IGT line goes to low level for about 130mS (time for C1 charging) and then goes to high level. 

Downloads
(only for www.settorezero.com subscribers)

Thursday, November 4, 2010

How to control 16 leds with only 3 I/O

The idea is quite simple: using a shift register to drive a led matrix using only few I/O of a microcontroller. Here I'll show you a my idea on how to drive 16 leds using only 3 I/Os with a Latched Shift Register 74HC595:




The microcotroller is connected to this circuit using the lines I've named as CLOCK, DATA and LATCH. 

The 74HC595 has a shift register and a latch. Incoming data are sent into shift register  using pin 14 (DS, serial data in) and pin 11 (SH_CP, Shift register clock). When we've  finished to sent serial data, we must  transfer data from shift register to the latch pulling high the pin 12 (ST_CP, Storage clock). If pin 13 (OE, output enable) is pulled down, the output pins (Q0-Q7) will reflect the latch status. Pin 10 is the Master Reset, pulling it down will cause the reset of the shift register. Pin 9 is serial data out and is used to drive more 74HC595.

We must feed data on DATA line using CLOCK and keeping LATCH down. When we have finished to send data, LATCH line must be pulled high and data are transferred from shift register to latch and value is displayed on leds.  We must pull LATCH down before start a new transfer but leds will remain in actual state. This is possible because pin 13 (OE = output enabled) is always low and then outputs are always enabled.

In order to display a value on 16 leds, data must be multiplexed. Entire first row will be lighted from serial value 0001 1111 : remember that high nibble drives the columns, low nibble drives the rowss. Entire second row will be lighted sending value  0010 1111 . Second led of third row (row=3 column=2) will be lighted sending value 0010 0010 and so on. Using a latched shift register will prevent the ghosting effect on leds.

Here there is an article in italian language I've written about using a shift register 74LS164 with a picmicro microcontroller. The informations and some code are about the same for 74HC595. The only two difference are:


- on 74HC595 data are sent from MSB to LSB, then the first bit you send on data line will be the bit n°8
- after you've send data, you must enable and then disable latch.

I have successfully tested this circuit. I've written a very long article on how to use this circuit witch a picmicro microcontroller. Article is in italian language, you can find it  clicking here

There are some examples here on how to use one or more 74HC595 with Arduino.

Downloads

74HC595 datasheet

Sunday, October 31, 2010

Processing NMEA strings with a microcontroller

This is only a sketch I've done some months ago. I've translated it into code and it does operate very well!!!

Here is an example of the software (written in C), based on the following flowchart, running on a PIC16F877A:


The purpose is to process NMEA strings from a GPS unit. Only the $GPRMC sentence is evaluated.

Download of flowchart is reserved to settorezero.com subcribers:

Saturday, October 30, 2010

Dismantling an HUAWEI E1550 HSDPA USB Stick

I've reading, some day ago, of a cheap method to add an sms-board to our electronics project using picmicro, arduino or other microcontrollers.

The method is quite simple and very very cheap: use a cheap GSM/USB modem! In the following link is described how to do this using a GSM/USB modem SKU12057: http://finch.am/projects/arduinogsm/ 

Modems usable to do this hack must support AT Commands. Once we have the command list of the main chip, interface modem to a microcontroller via an UART connection is matter of minutes!

I've a HUAWEI E1550 HSDPA USB Stick, distributed in Italy by mobile phone operator 3. I've opened it to see what chip uses. I'll show you some pics:

Front
Rear
The two screws to remove are covered by a little piece of white adhesive paper:


Internally the circuits are covered by a small aluminum covers:



Once cover are removed, the chips becomes visible:


In this side, between the sim-card socket and the metal protection, there are some test-pads. Looking at Google I think those pads are used for JTAG programming of the chip. The chips in this side are:
  • Qualcomm RTR6285 (RF Radio Frequency transceiver for GMS/UMTS/GPS)
  • PM6658 (Power Management IC)


On this side the chips are:
  • Hynix "Hycouelom" F3R-2S60E (A flash memory where software and drivers for the use of USB stick are stored. This stick, in fact, is recognized as USB combo device and appears like a removable unit)
  • Avago AFEM7780 (UMTS2100 4x7 Front-end Module (FEM))
  • Qualcomm MSM6246 
The Qualcomm MSM6246 is the main CPU: HSDPA Modem with integrated Assisted GPS, High speed USB support and some other features not used by this USB stick such as 3Mpix camera support and QVGA video playback.

This chip is used also in some mobile phones (like the Samsung S8000) and I've not find useful info's... Only one link talking about this chip and Jtag: http://www.omnia-repair.com/forum/topic/zte-mf636msm6290-jtag-pinout

Datasheets 
Warning: those downloads are only available for settorezero.com subscribed users!

Avago AFEM7780 (UMTS2100 4x7 Front-end Module (FEM)) 

 
If you have datasheets and infos for use this usb stick as a UART modem... you're the welcome!!

XFS filesystem and Samsung LEDTVs

I've got a Samsung LEDTV, model UE40C7000W.Those new tvs can record and playback tv programs by connecting an USB flash drive. First time USB flash drive is attached, the tv requires to format the new drive.

File system used is XFS from Silicon Graphics (SGI). This filesystem seems was preferred due to high performance on video streaming and large files handling. Unfortunately windows operating system don't recognize this filesystem (but UBUNTU does!). The only software I've found to be able to read XFS partition on Microsoft Windows is UFS Explorer.

But... UFS Explorer is no free software and the freely downloadable version can recover only files < 64Kb... Sigh!

Some people says LLTools can read XFS partitions. Is no true! LLTools can read Linux Partitions (Ext2).

The drive formatted by led tv appears to be organized in only 2 folders: "database" (in lower-case) and "CONTENTS" (in upper-case). Recorded programs are placed into "Contents" folder. Each recorded program is made of 5 files, all named as YYYYMMDDHHmmss (timestamp of start of recording).  Some recordings have also a preview image in JPG format (but the file name is different).

The 5 files have different extensions:

.ckf -> ?
.inf -> a binary file with some informations about recording (title, channel etc)
.mdb -> ? (is no a Microsoft Office Access file!!)
.mta -> is an XML file Samsung calls SMVideoEngine (Samsung Metadata Video Engine)

Mta Files looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!--Samsung video metadata file generated by SMVideoEngine (Samsung Metadata Video Engine) v1.0, June 2009. (http://www.samsung.com)-->
<SEC:SECMeta xsi:schemaLocation="urn:samsung:metadata:2009 Video_Metadata_v1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SEC="urn:samsung:metadata:2009">
    <SpecVersion>1.0</SpecVersion>
    <MediaInformation>
        <VideoLocator>
            <MediaUri>file://samsung_content.con</MediaUri>
        </VideoLocator>
    </MediaInformation>
    <ContentInformation>
        <Chaptering>
            <ChapterSegment>
                <KeyFrame>
                    <InlineMedia>

[...a lot of alphanumeric chars...]

</InlineMedia>

                </KeyFrame>
                <MediaPosition>
                    <MediaTime timePoint="0"/>
                </MediaPosition>
            </ChapterSegment>
        </Chaptering>
    </ContentInformation>
</SEC:SECMeta>

.srf -> is the video file (finally!). GSpot says it is an MPEG2-encoded video but I think that's no true... In fact no software (VLC included!) can read this file! SGRUNT!

 I don't understand how jpg image is associated to recording... (into the .inf file? or into .mta or database?)

The "CONTENTS" folder contains also some other files like Timeshift (.inc, .mdb, .ckf).

The "database" folder contains only 2 files: ace.dat and ace.log. The two files are binary. Ace.dat starts with:
AceDB Created By Insun Kang, Young-Seok Kim, Kyoung-Gu Woo, Heegyu Jin, Kyung-Sub Min, Taewon Lee, Dongseop Kwon, KyungWha Hong, Shin HoChul, Ki Yong Lee, DongJin Choi, Ilhwan Choi, Dongjoon Hyun, Seokjin Hong, Ki Yong Lee, SangJung Woo, Hyoungmin Park, Chuho Chang

If you have some informations on:
  • how to read XFS partitions under Windows using a free software
  • the meaning/scope of files created by TV
  • how to read "ace" database
  • how to convert .SRF movie
please leave a comment.