Raspberry Pi

Remove the annoying SSH message when Raspbian is starting

Easy! Run ‘sudo apt-get purge pprompt’

Advertisements
Raspberry Pi

SDL2 on Raspberry 1.0 running Minibian (FAILED)

UPDATE 2: I did the same thing on Raspbian and the compilation worked. See this.

UPDATE 1: This didn’t work, sorry guys. I couldn’t figure it out. Tried everything, running out of time…giving up…I’m going to try to make the game another way.


I have the very first Raspberry Pi, which I believe is a 1.0. I’m trying to make a game with it and I decided to use SDL. The goal is to run SDL without X, ie from console.

The first thing I needed was a lightweight distro for the RPi. I’m using Minibian because I’ve used it before and it works. Instructions for this are pretty simple:

  1. Download Minibian (https://minibianpi.wordpress.com/download/)
  2. Use Rufus to flash it to an SD Card
  3. Run the RPi and resize the partitions (https://minibianpi.wordpress.com/how-to/resize-sd/). Read the instructions carefully especially the part about aligning the partitions.
  4. Install nano
  5. If you need Wifi, install firmware-realtek (assuming you have a Realtek based dongle) and wpasupplicant. For more info visit https://minibianpi.wordpress.com/how-to/wifi/

Next step is to install SDL:

DON’T INSTALL using the package manager, it doesn’t work. You need to compile from scratch.

  1. Install these packages required for compiling SDL (not sure if the mesa libraries are required):
    apt-get install build-essential libfreeimage-dev libopenal-dev libpango1.0-dev libsndfile1-dev libudev-dev libasound2-dev libjpeg-dev libtiff5-dev libwebp-dev automake
    apt-get install libraspberrypi-dev raspberrypi-kernel-headers
    apt-get install libegl1-mesa libegl1-mesa-dev
  2. Get SDL2 (https://www.libsdl.org/release/SDL2-2.0.5.tar.gz)
    mkdir install && cd install
    wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz
    tar zxvf SDL2-2.0.5.tar.gz
    cd SDL2-2.0.5
  3. Configure and build
    ./configure --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11
    make
    make install
  4. FAIL!

 

 

 

Uncategorized

Eclipse (Neon.2) and SDL2

After much trial and error, here are the instructions to using Eclipse and SDL2:

  1. Download and install Eclipse Neon.2 for C/C++
  2. Download and install MingW
    1. Install to C:\Mingw\
    2. In the bin folder, copy gcc.exe and rename it to mingw32-gcc.exe
  3. Download SDL2 MingW version and unzip to C:\SDL2
  4. Add C:\mingw\mingw32\bin to your PATH
  5. Copy SDL2.dll to C:\Windows\SysWOW64 if running 64-bit or C:\Windows\System32 if running 32-bit
  6. Run Eclipse
  7. Create a new C project and select MingW toolchain
  8. Add a new C source file and add this code
    #include <SDL.h>
    
    int main (int argc, char** argv) {
     // Create window
     SDL_Window* window = NULL;
     window = SDL_CreateWindow ( "Hello World!", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN );
    
     // Setup renderer
     SDL_Renderer* renderer = NULL;
     renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED);
    
     // Set background color to red
     SDL_SetRenderDrawColor( renderer, 255, 0, 0, 255 );
    
     // Clear window
     SDL_RenderClear( renderer );
    
     // Create a square at ( 50, 50 ) with 50 width/height
     SDL_Rect r;
     r.x = 50;
     r.y = 50;
     r.w = 50;
     r.h = 50;
    
     // Fill square with blue color
     SDL_SetRenderDrawColor( renderer, 0, 0, 255, 255 );
     SDL_RenderFillRect( renderer, &r );
    
     // Draw everything to screen
     SDL_RenderPresent(renderer);
    
     // Wait for 5 seconds
     SDL_Delay( 5000 );
    
     // Close window and exit
     SDL_DestroyWindow(window);
     SDL_Quit();
    
     return EXIT_SUCCESS;
    }
  9. Add “C:\SDL2-2.0.5\i686-w64-mingw32\include\sdl2” to the Project “Include”
  10. Add “C:\SDL2-2.0.5\i686-w64-mingw32\lib” to the Project “Library Paths”
  11. Add “mingw32, sdl2main, sdl2” (in that order) to the Project “Libraries”
  12. Compile and run! 🙂
Programming, WPF

IValueConverter

If you’re making an WPF Visual Basic application and make a custom IValueConverter for the first time you’ll probably see this message

“The name <your_class> does not exist in the namespace “clr-namespace:<your_application>

Here’s a screenshot from the XAML Designer:temp1

The fix is surprisingly easy:

  1. Change that line to “<local:Application…”
  2. Build the solution
  3. Change it back to “<local:ID2Converter…”
  4. Voila!

In case you’re wondering, my xaml.vb file looks like this:

Imports System.Globalization

Public Class ID2Converter
 Implements IValueConverter

 Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.Convert
 ' blah blah blah
 End Function

 Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
 ' blah blah blah
 End Function
End Class

Public Class MyClass
' blah blah blah
End Class

So, you can put the IValueConverter in the same xaml.vb as the class using it. No need to declare namespace etc 🙂

Arduino, Programming

Arduino + DS1307 RTC

Another demo for interfacing an Arduino with the DS1307 Real Time Clock. The board I used (see here) also has an integrated 24C32 32K EEPROM which we won’t worry about in this demo.

Here’s a picture of my setup:

IMG_20151121_202254

Materials Used:

  • Arduino Uno R3
  • 16×2 LCD Shield
  • DS1307 board (I used this one) but you could use this one too
  • CR2032 button cell

Wiring details:

(NOTE: If you’re using the same board as me then wire to the side of the board with the pins SQ, DS, SCL, SDA, VCC, GND & BAT)

  1. Uno’s 5V (via LCD Shield) to RTC’s 5V
  2. Uno’s GND (via LCD Shield) to RTC’s GND
  3. Uno’s Analog Pin 4 (via LCD Shield) to RTC’s SDA
  4. Uno’s Analog Pin 5 (via LCD Shield) to RTC’s SCL
  5. Leave the other pins unconnected
  6. Put the button cell in!

You can find the code here. And voila! 🙂

Arduino, Programming

Arduino + HR-SR04 Ultrasonic

I wanted to try an Ultrasonic sensor so I bought the cheapest one I could find, the HR-SR04. I used this tutorial to learn about the ultrasonic. Basically I thought the Ultrasonic would provide an analog signal with the distance…well I was wrong. Distance is calculated based on the time taken for an echo signal to be sent and received.

Here’s a picture of my setup.

IMG_20151121_160922

Materials used:

Wiring is easy:

  1. Uno’s 5V (via LCD Shield) to sensor’s 5V
  2. Uno’s GND (via LCD Shield) to sensor’s GND
  3. Uno’s Digital Pin 0 (via LCD Shield) to sensor’s ECHO
  4. Uno’s Digital Pin 1 (via LCD Shield) to sensor’s TRIG

You can find the code here. And voila! 🙂