Sunday, April 8, 2018

Stream of Prime Numbers

Create an endless stream of prime numbers - a bit like IntStream.of(2,3,5,7,11,13,17), but infinite. The stream must be able to produce a million primes in a few seconds.

Tuesday, October 3, 2017

ESP8266 vs ESP32

SpecificationsESP8266ESP32
MCUXtensa Single-core 32-bit L106Xtensa Dual-Core 32-bit LX6 with 600 DMIPS
802.11 b/g/n Wi-FiYes, HT20Yes, HT40
WiFi Security?WEP, WPA/WPA2 PSK/Enterprise
Hardware Accelerated Encryption?AES/SHA2/Elliptical Curve Cryptography/RSA-4096
BluetoothNonedual-mode: Bluetooth 4.2 BLE or classi
Typical Frequency80 MHz240 MHz
SRAM160 KB520 KB
FlashSPI Flash, up to 16 MBSPI Flash, up to 16 MB, memory mapped to CPU code space.
GPIO1736
Hardware/Software PWMNone/8 channels1/16 channels
SPI/I2S/I2C/UART 2/1/2/2 3/2/2/3
ADC10 bit12-bit, 18 channels
DACNone2
CANNone?
Ethernet MAC Interface None 1
Touch Sensor None Yes
Temperature SensorNoneyes
Working Temperature-40 C - 125 C-40 C - 125 C
Operating Voltage?2.3V to 3.6V C
Power Consumption 77 μA5 μA power consumption in Deep-sleep

Reference: http://espressif.com/en/products/hardware/esp32/overview

My protoboard


Friday, September 29, 2017

ZigBee for IoT

The ZigBee and Z-Wave short-range wireless technologies are used for remote monitoring and control. However, their specifications and applications are different. Both technologies are ideal for home-area networks (HANs), which is becoming an in.


Differences between ZigBee and Z-Wave:


TechnologyFrequencyModulationData RateRangeApplications
ZigBee902 to 928 MHz (Americas and Australia)2.4 - 2.483 GHz (ISM)BPSK (900 MHz band) or
OQPSK (2.4 GHz band)
250 kbps10 mHome Automation, Smart Grid, Remote control
Z-Wave908.42 MHzGFSK9.6/40 kbps30 mHome Automation, security


ZigBee
It is ratified in the IEEE’s 802.15.4 personal-area network (PAN) radio standard. ZigBee is an open wireless standard from the ZigBee Alliance. The IEEE 802.15.4 standard provides layer 1 (physical layer, or PHY) and layer 2 (media access controller, or MAC) of the network, while the ZigBee stack software provides the network and application layers.

The Zigbee protocol is designed to communicate data through hostile RF environments that are common in commercial and industrial applications.

Zigbee protocol features include:
  • Support for multiple network topologies such as point-to-point,
  • point-to-multipoint and mesh networks
  • Low duty cycle – provides long battery life
  • Low latency
  • Direct Sequence Spread Spectrum (DSSS)
  • Up to 65,000 nodes per network
  • 128-bit AES encryption for secure data connections
  • Collision avoidance, retries, and acknowledgments (CSMA/CA)

ZigBee Physical Layer
ZigBee PHY operates in various bands, but the most common one is in the 2.4 GHz band. It uses offset quadrature phase-shift keying (OQPSK) that transmits two bits per symbol. In 900 MHz band, it uses BPSK for modulation.  The radio uses DSSS for digital streaming.

There are three (3) kind of devices in ZigBee:
  1. ZigBee Coordinator (ZR)
  2. ZigBee Router (ZR)
  3. ZigBee End Device (ZED)

Tuesday, September 26, 2017

Hot skills in Embedded and IoT

Based on my observation in the job market, the following skills are currently in demand in embedded systems surrounding IoT development:

  1. 802.11 (WiFi)
  2. Bluetooth, especially Bluetooth 4.0 + Low Energy (BLE) or newer
  3. Zigbee (IEEE 802.15.4)
  4. Z-Wave: Based on ITU G.9959 (PHY) and Z-Wave Application layer
  5. Bonjour (mDNS/DNS-SD)
  6. SSDP (Simple Service Discovery Protocol)
  7. OCF (Open Connectivity Foundation's uPnP Device Control Protocol)
  8. TCP/UDP
  9. TLS (Transport Layer Security)
  10. CoAP (Constrained Application Protocol; RFC-7252)
  11. HTTP, especially RESt API
  12. MQTT (Mosquitto)
  13. MultiThread
  14. Websockets
  15. RESTful (Representational State Transfer) architecture
  16. Rust (Rust is a programming language that’s focused on safety, speed, and concurrency)
  17. Jenkins
  18. XML
  19. LWM2M
  20. SQS
  21. AMQP
  22. Kafka
  23. AWS (Amazon Web Service)
  24. Microsoft Azure
  25. I2C
  26. SPI
  27. Asynchronous serial/UART programming
  28. Linux Kernel and Driver development



Thursday, September 21, 2017

Pointer to certain address in memory

In embedded system where we are working with microcontroller, many times we find a scenario where we need to access a memory-mapped register in the MCU.  How do we do that in generic way (for example with GCC compiler)?

The answer is to write it like below:

volatile <type> *<varname> = (<type> *)<address>

For example:

#include <stdio.h>

volatile char *var = (char *)0x1000;

int main()
{
    if (*var != 0)
        puts("NOT NULL!");
}

rendered into x86 assembly (64-bit Intel CPU) as:
...
...
.LC0:
        .string "NOT NULL!"

main:
movq var(%rip), %rax      # rax = address of var
movzbl (%rax), %eax         # eax = *var
testb %al, %al
jne .L9
xorl %eax, %eax
ret
.L9:
pushq %rax
movl $.LC0, %edi
call puts
xorl %eax, %eax
popq %rdx
ret

...
.LCOLDE1:
.section .text.startup
.LHOTE1:
.globl var
.data
.align 8
.type var, @object
.size var, 8
var:
.quad 4096           # or 0x1000