The MILK-V DUO is notable for it's multicore architecture.

This project will highlight the ability to exchange data between a core running Linux and another executing an Arduino Sketch.

The Linux core executes a 'C' program which runs an endless loop reading the internal temperature of the core and then using the inter-core mailbox to send the temperature reading to the Arduino core.  The Arduino core is running a sketch which receives the mailbox interrupt and displays the temperature value on an I2C OLED display.


To get all of this started I highly recommend you look through some of the previous blogs in my Milk-V Projects List which will help get your development environment setup.

This project illustrates 4 major concepts on the MILK-V Duo.

  • Using the /sys filesystem to read the internal temperature on the Linux core.
  • Sending this reading to the Arduino core using the asynchronous (interrupt) mailbox.
  • Receiving the mailbox interrupt on the Arduino core.
  • Displaying the reading on an I2C OLED display using an Arduino sketch.

The details are, of course, available in the source Files.  The highlights include:

  • #define T_FILE "/sys/devices/virtual/thermal/thermal_zone0/temp"
  • fread( temp, 1, 3, tf );  // this reads the 3 most significant bytes of the temperature.
  • tempr = atoi( temp );  //  convert the reading to an integer
  • fd = open( RTOS_CMDQU_DEV_NAME, O_RDWR ); // open the mailbox driver file
  • cmd.param_ptr = tempr;   // put the reading into the mailbox structure
  • ioctl(fd , RTOS_CMDQU_SEND_WAIT, &cmd);    // here we send the mail to the RTOS core

The tempr variable contains the 3 most significant bytes of the temperature reading, so it is in tenths of a degree Celsius.  This value is placed into the mailbox structure and passed to the Arduino core using an ioctl() function of the RTOS_CMDQU driver file.

The Arduino sketch is running a continual loop which flashes some eye gestures then displays the received temperature on a SSD1306 ICC OLED screen.

The line mailbox_register(0, showmsg);   attaches the "showmsg" function to the incoming mailbox interrupt.  The temperature is retrieved with the Temp = cmdq->param_ptr; instruction.  The 'Temp' variable is displayed to look like a decimal fraction on the OLED in the loop function.

 display.print( Temp/10 );
  display.print( "." );
  display.print( Temp%10 );
  display.print( " C" );


Please keep in touch - I always welcome your comments, either here or on the YouTube video.