Translate

Sunday, May 22, 2016

CAUTION ! When update is critical

Long long time since my last post.
I'm still around but very very busy with the job and other activities.
I have many projects that needs my attention, halted, waiting for better time.

Among the many things I have to do and I'm doing, after long time I decided that it was necessary to finally upgrade my server from the 15.04 Ubuntu to the latest LTS Ubuntu distro, the 16.04 LTS.
As usual when there is an upgrade, not the usual update, I'm always quite nervous.
In the past almost every time I ended up to format everything from the scratch since the upgrade always failed along the way.

So after the usual backup of data, I started the upgrade.
First I had to upgrade from the 15.04 to the 15.10.
It took about 3 hours and I "lost" only a couple of services.
Then, since the system was still working I decided to risk everything and upgrade from the 15.10 to the 16.04 LTS.

It worked ! It took an additional couple of hours crunching, deleting old libraries, clean up the system, upgrade configurations but it worked.
But I had to pay a price.

After restoring the broken services, sometime simply re-installing a new version, I discovered that ALL my websites based on Joomla hosted on the server, were off line.
Dead. All dead.

Ubuntu 16.04 LTS installs ONLY PHP 7.x. Older versions of PHP are not supported, actually the notes suggests to DON'T Try to install PHP 5.x at all.
And my Joomla websites were bases on old versions of Joomla, requiring PHP 5.x or even older ones.

Only Joomla 3.5 supports PHP 7.0 so I ended up with very few choices :

  1. erase the Ubuntu 16.04 LTS from the server and install something older
  2. try to install other PHP versions other than the 7.x on the server
  3. install virtualbox on the server and set up a old version of Ubuntu only for the web servers
  4. install Joomla 3.5 and rebuild all the websites converting from the old versions
Let's cut the suspance :) in the end I opted for the last option.
Ubuntu 16.04 LTS works really nice on the server, the only flaw is PHP.
So far the server is much faster and stable than before.
Installing older version of Ubuntu was not really a choice.

The choice number 2 required to have a lot of time to overcome the errors certainly coming out as well as the choice 3.
I did try to install virtualbox but I ended up with errors.
The version I tried to install was incompatible somehow with the 16.04 and not yet enough support or other people doing that to find solutions fast.

So I decided to recreate all my websites from the scratch, using Joomla 3.5.
It will take some time to convert the data (I'll maybe write another article to describe the pain for this operation :) )  but in the end is the least expensive, safest way to proceed and I'll end up with a better working websites.

So, if you are planning to upgrade your machine to Ubuntu 16.04 LTS and you need PHP 5.x or older ... BE VERY CAREFUL.
You'll lose a lot but also gain a lot from other areas.

Saturday, November 14, 2015

Timer for UV box

Ok, here the deal.
The need is to develop a timer, faster, capable to control up to 16 UV fluorescent bulbs.
Up to 2 hours, 1 second precision, display to show the countdown and menu' management, digital encoder for input, pushbuttons/LEDs.

It can be done in thousands ways, but this time I'll try to put it together using Energia and a BIG help from Roberto.

Wednesday, November 4, 2015

Embedded RPOf

The next thing to do about the RPOf is to embed it in a piggy back board over the Raspberry Pi.
The Raspberry Pi GPIO connector has both the 3.3V and 5V rail available, so to have a more compact system, embedding the RPOf on the "shield" connected to the Raspberry Pi, can helps to reduce the space and number of boards.

Friday, October 30, 2015

Working on the iRis project

[To be updated !]

A step-by-step guide to work on git for the iRis project.
If you are new on git and github, read this article first.

The iRis project is on github, so if somebody wants to join it, or just follow the progress, can clone the git repo for iRis.

Working on RPOf project

Here a step-by-step guide to work on git for the RPOf project.
If you are new on git and github, read this article first.

Working on my projects

Here a step-by-step guide to work on git for some projects I maintain.

This guide assumes:

  • you like Linux, you USE Linux
  • you know how to work with the terminal
  • the instructions are based on Ubuntu, but they should be easily used on other systems.
    The main difference could be the application to install code. apt-get for Ubuntu, yum for Red Hat/CentOS, ecc.
  • you know how to set up a cross compiler for different microcontroller under Linux

Introduction


The most important thing to remember working with git, is that normally ALL the operations are LOCAL to your machine !
Only few specific and explicitly called operations operate on a remote server, in our case, github.

Specifically :

  • The first time, when we clone the project from github
  • Every time we want to update our code from github
  • Every time we want to save our work on github

First time

git Installation


The first time we want to clone the project from github.
How we do that ?
First of all we must have git on our machine.
So if you don't already installed it, open a terminal and type :

  • sudo apt-get update
  • sudo apt-get install git


(note, I'm using for this article, the git version 1.9.1 on a Ubuntu 14.04 LTS)

After the installation, is better to set it up with some basic info :

  • git config --global user.name "your name"
  • git config --global user.email "youremail@domain.com"
  • git config --list will show the configuration for your git
For example :

git config --global user.name "John Smith"
git config --global user.email "jsmith@mystery.com"

I'm not sure if is valid for every type of operation, but it is possible github will require a SSH key in order to clone/update a project.
In that case I strongly recommend to follow this brief tutorial about how to generate and deploy an ssh key with github.

At this point you are ready to clone the project from github !

Clone a project

Cloning is the act that duplicate on your hard drive what is present in a remote git repository, in this case github.
The cloning is strongly suggested in case you want to collaborate to the project.
Cloning the project recreate on your local machine the project and it's history and allows to merge it back on github if you do modifications.

First of all create or go on a directory that will host the project.
For example, create a directory called SteveProjects on your home environment :
  • cd ~
  • mkdir SteveProjects
  • cd SteveProjects
Now is possible to use git to clone a project, with the command :

  • git clone URL_repository
That's it !
On your directory Projects, will exist a directory called as the project name, containing the project.

Download a project


In case you are not interested to collaborate to the project but wants to have the project on your machine, or in case you don't want to install git or generate SSH keys, from github is possible to download the project as a zip file.

Update project

Now that you have the project on your machine, to keep it updated is even easier.
Simply go in the project directory and issue the command : git pull

  • cd ~/Projects/project_name
  • git pull
That's it !  If the code on the github is changed, it will be updated on your machine

Working on the project

Commit the project


If you want to collaborate to a project, you can modify the code on your machine, and keep track of the modifications locally, using git.
Issuing the command git status returns the status of the modifications made to the code.

Every time you modify a file, git status will indicate a modification.
Every time you will have to add it with:

git add file_name

git add * will add all the modified files.

Then it will be possible to commit the file with:

git commit file_name

All these operations are LOCAL to your machine !

If you are a registered collaborator to the project (ask me), then you should be able to "push" your modifications in the github with:

git push

Working protocol


In order to reduce the conflict between developer, I suggest this protocol:


  1. Clone the project
    git clone URL_of_github_project
  2. Create a branch
    git checkout -b branch_name
  3. Work on your modifications, add and commit regularly
  4. When is time to push the modifications:
    git push origin branch_name
  5. If allowed, merge the branch on the master.



Tuesday, October 13, 2015

iRis project - an introduction

The purpose of the iRis project is to have a "head" for medical training purpose related to eyes illness.
Basically the idea is to build a "eyes simulator" capable to react to the light like an eye does, in order to simulate  different types of illness retina/nerve related.

Friday, August 14, 2015

Cooling the server area

Problem, cool down the server area.

The server is placed under a stair and the server area is insulated.
The area is in contact with the garage and the laundry room and of course the garage of course is not an insulated area, but the laundry it is.
Thus the idea : drill a hole in the stairs and connect a fan to aspire the fresh air from the laundry room.

Tuesday, August 11, 2015

MSP430 - Energia and Grove


I do have few Arduino around.
Like many people I bought some of them because ... well, I don't know, I guess at the time it was the news, to see what it is.
And I didn't like it much.


Saturday, August 8, 2015

MSP430 - I2C library

There are many different library out there to handle I2C with the MSP430.
Some of the libraries are also "official", from TI.

I found a nice and simple C library to handle the I2C with USI is on github and apparently is easy to deploy and use.
This article contains some notes about how to deploy and use the library, closing some missing practical information.

Let's start with ... the hardware.

Hardware


The library was originally developed and tested on an MSP430g2452.
It surely can work on any MSP430 family member that has a USI, that's was anyway my initial intent.
I tried to use an MSP430f2013 but in the end I opted to buy some MSP430g2452 because the 2013 doesn't have enough memory (only 2K ROM) to handle protocol and the rest of the code needed for a project.
The MSP430g2452 has 8K ROM.

After choosing the microcontroller, the attention was concentrated on the I/O pin to use.
Note ! Initially I'm experiment using a Launchpad.
The library expects to use the USI pins, i.e. the P1.6 for the SCL and the P1.7 for the SDA.
Apparently there is NO need to bother with the I/O ports to inform the MSP430 that the 2 pins are dedicated to the USI in I2C mode.
Is enough to program the USI control register to do that, and that is taken care in the i2c_init function provided by the library.

Important !!! The P1.6 on the Launchpad is connected to the green LED !
Remove the jumper on that LED in order to have something working !

Software

Compile it


The library presumably is written for IAR or other commercial system.
In order to compile it with Mspgcc few modifications are necessary.


  1. Remove the specific include of the msp430g2452 header from usi_i2c.c
  2. Add the generic include of msp430 in the usi_i2c.h
  3. Remove the include of the stdint.h header from usi_i2c.c and move in the usi_i2c.h
  4. Change the interrupt declaration, from:
    #pragma vector = USI_VECTOR
    __interrupt void USI_TXRX(void)
    {
      switch(__even_in_range(i2c_state,12))

    to

    __attribute__((__interrupt__(USI_VECTOR)))
    void Usi_txrx (void){  switch(__even_in_range(i2c_state,12))
  5. Move the inline function i2c_done() from the header file (usi_i2c.h) into the module (usi_i2c.c) and leave a function prototype for that function in the usi_i2c.h header file
With these modifications I was able to compile the library using mspgcc.

I also fixed a bug that was preventing the library to read more than 8 bit at a time.
In the usi_i2c.c file, in the interrupt function Usi_txrx change the highlighted line :

..................................................................
..................................................................
case I2C_RECEIVED_DATA:       // received data, send ACK/NACK
    *i2c_receive_buffer = USISRL;
    i2c_receive_buffer++;
    USICTL0 |= USIOE;           // SDA = output
    if(i2c_sequence_length > 1) {    
      // If this is not the last byte
      USISRL = 0x00;                // ACK 
..................................................................
..................................................................

with

..................................................................
..................................................................
case I2C_RECEIVED_DATA:       // received data, send ACK/NACK
    *i2c_receive_buffer = USISRL;
    i2c_receive_buffer++;
    USICTL0 |= USIOE;           // SDA = output
    if(i2c_sequence_length > 0) {   // TheFwGuy MOD !!!    
      // If this is not the last byte
      USISRL = 0x00;                // ACK 
..................................................................
..................................................................


Use it


The library has only three "public" functions and act as Master.
Let see how to use it.

i2c_init


The first public function is called i2c_init and like the name imply, is used to initialize the USI and set up the MSP430 to use it.
It must be called once, preferably after other basic I/O initializations happens.
After that, the "system" should be able to send out I2C messages.

Example:

        i2c_init(USIDIV_5, USISSEL_2);

The first parameter determine the division applied to the input clock.
USIDEV_0 divide by 1, USIDEV_1 divide by 2, USIDEV_2 divide by 4 and so on (see MSP430 Family user guide - USICKCTL register).
The second parameter determine the source of the clock (see MSP430 Family user guide - USICKCTL register).
In the example above the source for the clock is the SMCLK divided by 32.

i2c_done


This function returns TRUE (1) or FALSE (0) to indicate if a transaction is running.
The I2C messages are sent via interrupt so it is possible that the main program is ready to send another sequence when the system is still handling the previous sequence.
So before to perform any request, better to see if the system is ready to accept it.
Example:

      if(i2c_done())
         i2c_send_sequence((uint16_t *)seq1, 2, (uint8_t *)recseq, 0);

or
      while(!i2c_done());

Strongly suggested to use it to prevent to start a sequence when another one is still running.

i2c_send_sequence

This is the main function and the most complex to handle.
Simply put, this function can send and receive information via I2C using a "sequence".
The sequence  is a series of word and commands.
i2c_usi.h  defines two commands :
  • I2C_RESTART
  • I2C_READ
The function has these inputs:

  • sequence
    sequence is a pointer to an array containing the I2C operation sequence that should be performed.
    It can include any number of writes, restarts and reads.
    The sequence is composed of uint16_t, not uint8_t elements.
    This is because the need  to support out-of-band signalling of I2C_RESTART and I2C_READ operations, while still passing through 8-bit data.
    The sequence uses the Bus Pirate I2C convention.
    The address must be prepared manually, adding the R/W bit.
    The address is prepared shifting the 7-bit I2C address to the left and add the R/W bit (0 to write, 1 to read).
    The examples above communicate with a device whose I2C address is 0x1c, which shifted left gives 0x38.
    For reads we use 0x39, which is (0x1c<<1)|1.

    So for example, to write at the address 0x39, the sequence would be:

    • 0x39 << 1 = 0x72
    And to read from the address 0x39:
    • (0x39 << 1) | 1 = 0x73
  • sequence length
    sequence_length is the number of sequence elements (not bytes).
    Sequences of arbitrary (well, 32-bit) length are supported.
  • received data
    received_data should point to a buffer that can hold as many bytes as there are I2C_READ operations in the sequence.
    If there are no reads, 0 can be passed, as this parameter will not be used.
  • wake up sr bits
    Used if you want to use the MSP430 in low power mode.

Building sequences


The sequences to send depends strictly to a specific component so there is no a generic suggestion if not to carefully read the datasheet of the component.