NewPing Library for Arduino (Ultrasonic Sensors)

hc-sr04-500x500

Пример:

// ---------------------------------------------------------------------------
// This example code was used to successfully communicate with 15 ultrasonic sensors. You can adjust
// the number of sensors in your project by changing SONAR_NUM and the number of NewPing objects in the
// "sonar" array. You also need to change the pins for each sensor for the NewPing objects. Each sensor
// is pinged at 33ms intervals. So, one cycle of all sensors takes 495ms (33 * 15 = 495ms). The results
// are sent to the "oneSensorCycle" function which currently just displays the distance data. Your project
// would normally process the sensor results in this function (for example, decide if a robot needs to
// turn and call the turn function). Keep in mind this example is event-driven. Your complete sketch needs
// to be written so there's no "delay" commands and the loop() cycles at faster than a 33ms rate. If other
// processes take longer than 33ms, you'll need to increase PING_INTERVAL so it doesn't get behind.
// ---------------------------------------------------------------------------
#include "NewPing.h"

#define SONAR_NUM     8 // Number or sensors.
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).

unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
unsigned int cm[SONAR_NUM];         // Where the ping distances are stored.
uint8_t currentSensor = 0;          // Keeps track of which sensor is active.

NewPing sonar[SONAR_NUM] = {       //   Sensor object array. Each sensor's trigger pin, echo pin, and max distance to ping.
  NewPing(50, 51, MAX_DISTANCE),   // 1
  NewPing(52, 53, MAX_DISTANCE),   // 2
  NewPing(38, 37, MAX_DISTANCE),   // 3
  NewPing(40, 39, MAX_DISTANCE),   // 4
  NewPing(33, 34, MAX_DISTANCE),   // 5
  NewPing(35, 36, MAX_DISTANCE),   // 6
  NewPing(24, 25, MAX_DISTANCE),   // 7
  NewPing(26, 27, MAX_DISTANCE),   // 8
};

void setup() {
  
  Serial1.begin(115200);
  
  pingTimer[0] = millis() + 75;           // First ping starts at 75ms, gives time for the Arduino to chill before starting.

  for (uint8_t i = 1; i < SONAR_NUM; i++) // Set the starting time for each sensor.
    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
}

void loop() {
  
  for (uint8_t i = 0; i < SONAR_NUM; i++) {       // Loop through all the sensors.
    if (millis() >= pingTimer[i]) {               // Is it this sensor's time to ping?
      pingTimer[i] += PING_INTERVAL * SONAR_NUM;  // Set next time this sensor will be pinged.
      if (i == 0 && currentSensor == SONAR_NUM - 1) oneSensorCycle(); // Sensor ping cycle complete, do something with the results.
      sonar[currentSensor].timer_stop();          // Make sure previous timer is canceled before starting a new ping (insurance).
      currentSensor = i;                          // Sensor being accessed.
      cm[currentSensor] = 0;                      // Make distance zero in case there's no ping echo for this sensor.
      sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
    }
  }
  // The rest of your code would go here.
}

void echoCheck() { // If ping received, set the sensor distance to array.
  if (sonar[currentSensor].check_timer())
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
}

void oneSensorCycle() { // Sensor ping cycle complete, do something with the results.

  for (uint8_t i = 0; i < SONAR_NUM; i++) {
    Serial1.print(i);
    Serial1.print("=");
    Serial1.print(cm[i]);
    Serial1.print("cm ");
  }

  Serial1.println();
}

VGA/HDMI переключение.

Данный метод не работает.

# To switch VGA/HDMI display mode in command line. e.g.
$ cb-display-tool -o 8 -m 11
# Note: can switch to the same resolutions only currently.

А вот если изменить script.fex

[disp_init]
disp_init_enable = 1
disp_mode = 0
screen0_output_type = 4
screen0_output_mode = 4
screen1_output_type = 2
screen1_output_mode = 14

То все работает.

Для конвертации из bin to fex : bin2fex script.bin > script.fex
для конвертации из fex to bin : fex2bin script.fex > script.bin

Новый прототип от U-Blox GSM/Arduino/Mbed все в одном.

u-blox-C027

The u-blox-C027 is a complete starter kit that allows quick prototyping of a variety of applications for the Internet of Things. The application board has a MAX-7Q GPS/GNSS receiver and a LISA or SARA cellular module, enabling straightforward development of locationaware, global communicating ap.

c027-pinout_1

Features

Modules

  • LISA-C200, LISA-U200 or SARA-G350 cellular module
  • MAX-7Q GPS/GNSS receiver

NXP LPC1768 MCU

  • High-performance ARM(R) Cortex(TM)-M3 running at 96MHz
  • 512 KByte on-chip FLASH
  • 64 KByte on-chip SRAM

Interfaces and electrical data

  • A standard-based header connector with
    • 6 analog inputs,
    • 9 PWM capable outputs,
    • 22 GPIOs,
    • 1 x SPI,
    • 1 x I2C,
    • 1 x UART
    • 1 x I2S
  • GNSS antenna SMA connector for external GNSS antenna
  • Cellular antenna SMA connector for external cellular antenna
  • Ethernet RJ45 connector
  • CAN screw terminal connector
  • SIM mini SIM card holder
  • USB mini USB with mbed Interface
    • CMSIS-DAP
    • Drag and drop programming
    • serial port
  • Power supply 7-17v @ 900mA (power jack and header connector pins)
  • IO voltage 3.3 V output, 5 V compatible input

Источкик: http://mbed.org/platforms/u-blox-C027/

Cubieboard LUBUNTU/LINARO – locale: Cannot set

При выполнения некоторых команд появляется вот такая ошибка.

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "ru_RU.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

Решение проблемы:

sudo apt-get install --reinstall language-pack-en
sudo locale-gen
sudo dpkg-reconfigure locales
sudo locale-gen ru_RU.utf8

pcDuino + Python + Arduino via UART

Узнаем IP address который получила pcDuino через DHCP и посылаем его в Arduino через UART.

#!/usr/bin/env python

import socket
import fcntl
import struct
import serial
import time, os

def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', ifname[:15])
    )[20:24])

# Инициализация порта UART0

def uart_init():
    GPIO_MODE_PATH= os.path.normpath('/sys/devices/virtual/misc/gpio/mode/')
    GPIO_PIN_PATH=os.path.normpath('/sys/devices/virtual/misc/gpio/pin/')
    GPIO_FILENAME="gpio"

    pinMode = []
    pinData = []

    SERIAL = "3"

    for i in range(0,2):
	pinMode.append(os.path.join(GPIO_MODE_PATH, 'gpio'+str(i)))
        pinData.append(os.path.join(GPIO_PIN_PATH, 'gpio'+str(i)))

    file = open(pinMode[0], 'r+')
    file.write(SERIAL)
    file.close()
    file = open(pinMode[1], 'r+')
    file.write(SERIAL)
    file.close()

uart_init()

pcDuinoIPaddress = get_ip_address('wlan0')

arduino = serial.Serial('/dev/ttyS1',baudrate=115200,timeout=10)

arduino.write("["+pcDuinoIPaddress+"]")

arduino.close()