CyberPi is an open-source device.
This section provides the open-source materials that can help you obtain the underlying permissions on CyberPi, allowing you to:

  • Develop functions for CyberPi
  • Design blocks in Extension Builder for CyberPi
  • Enable CyberPi to work with third-party hardware
  • Develop extension boards and electronic modules for CyberPi

    Device schematic diagram

    The schematic diagram of a device can help you understand its hardware design.

    Schematic diagram of Halocode

    To understand the hardware design of Halocode, refer to its schematic diagram, as shown in the following figure.

Open-source Materials - 图1
halocode_V1_0.pdf
[For non-Yuque users, click halocode_V1_0.]

Schematic diagram of CyberPi

image.pngCYBERPI_V1_X (1).pdf [For non-Yuque users, click CYBERPI_V1_X.]
CyberPi_V1_0_PCB.pdf [For non-Yuque users, click CyberPi_V1_0_PCB.]
CyberPi_Gerber.rar [For non-Yuque users, click CyberPi_Gerber.]
Hardware License: License_cern_ohl_p_v2.pdf [For non-Yuque users, click License_cern_ohl_p_v2.]
Software License: GPL v3
Documentation License: CC BY-SA 4.0 International

3D model

If you want to design and print some 3D models to work with CyberPi, refer to the 3D model of CyberPi.

3D model of CyberPi

image.png
CyberPi.rar [For non-Yuque users, click CyberPi.]

3D model of Pocket Shield

image.png
Pocket Shield.rar [For non-Yuque users, click Pocket Shield.]

Third-party compatibility

You can use the 3-pin ports on Pocket Shield to connect and control third-party parts or modules, such as Arduino modules.

Related blocks and Python APIs are provided, as described in the following.

Blocks

image.png

Python APIs

**cyberpi.pocket.write_digital(val, port)**
Sets the digital input for the specified pin(s)
Parameters:

  • val: digital input
  • port: int or str, port where the pins are located

Setting range:
all
s1
s2
S1
S2
1
2

**cyberpi.pocket.read_digital(port)**
Obtains the digital input for the specified pin
Parameter:

  • port: int or str, port where the pins are located

Setting range:
s1
s2
S1
S2
1
2
An int value ranging from 0 to 1 is returned, where 0 indicates a low electrical level and 1 indicates a high electrical level.

**cyberpi.pocket.set_pwm(duty, frequency, port)**
Sets the specified pin(s) to output PWM signals with the specified frequency and duty cycle
Parameters:

  • duty: int, duty cycle of the PWM signals to be output; setting range: 0–100, in percentage
  • frequency: int, frequency of the PWM signals to be output; setting range: 1–2000, in Hz
  • port: int or str, port where the pins are located

Setting range:
all
s1
s2
S1
S2
1
2

**cyberpi.pocket.read_analog(port)**
Obtains the voltage at the specified pin
Parameter:

  • port: int or str, port where the pins are located

Setting range:
s1
s2
S1
S2
1
2
A float value ranging from 0 to 5 is returned, in volts.

For more information, see the Pocket Shield Operation Guide.

Extension Builder (recommended)

With the SDK and Python APIs provided by Makeblock, you can design various block extensions to meet your needs.

Designing an extension is not as difficult as you think. Trust yourself! You can be a developer.

Open Extension Builder.
image.png
For details about how to use Extension Builder, see the Extension Builder Developer Documentation.
For details about the Python APIs, see the Python API Documentation for CyberPi.
Courses for Extension Builder are on the way. Stay tuned!

SDK for developers

To modify the underlying firmware of CyberPi, you can view the corresponding Gitee project. Note that modifications on the firmware may cause the failure of some functions, but you can update the firmware of CyberPi on mBlock 5 to restore the functions, of course.

With the SDK for developers, you can develop CyberPi in another programming environment other than mBlock 5.

Arduino SDK

Arduino is a platform widely used in the open-source hardware field, and therefore we have designed an open Arduino SDK for CyberPi. You can click the following link to modify the firmware of CyberPi and program it based on the functions it provides by using Arduino.

Visit the Arduino SDK at https://github.com/Makeblock-official/CyberPi-Library-for-Arduino.

Currently, the firmware includes the source code of the drivers for the sensors, display, and LEDs, and available interfaces are encapsulated in the drivers.

Welcome to join us to make it more powerful! We will update this project continuously to develop more features for it.

Arduino examples

Some basic example programs are provided in the following. You can download the official Arduino IDE to update and use the firmware of CyberPi.

1. Button

  1. #include "cyberpi.h"
  2. CyberPi cyber;
  3. void setup()
  4. {
  5. Serial.begin(115200);
  6. cyber.begin();
  7. }
  8. void loop()
  9. {
  10. Serial.print("a:");
  11. Serial.print(cyber.get_button_a());
  12. Serial.print(" b:");
  13. Serial.print(cyber.get_button_b());
  14. Serial.print(" menu:");
  15. Serial.println(cyber.get_button_menu());
  16. delay(500);
  17. }

2. Joystick

  1. #include "cyberpi.h"
  2. CyberPi cyber;
  3. void setup()
  4. {
  5. Serial.begin(115200);
  6. cyber.begin();
  7. }
  8. void loop()
  9. {
  10. Serial.print("x:");
  11. Serial.print(cyber.get_joystick_x());
  12. Serial.print(" y:");
  13. Serial.print(cyber.get_joystick_y());
  14. Serial.print(" pressed:");
  15. Serial.println(cyber.get_joystick_pressed());
  16. delay(500);
  17. }

3. LED

  1. #include "cyberpi.h"
  2. CyberPi cyber;
  3. void setup()
  4. {
  5. cyber.begin();
  6. }
  7. float j, f, k;
  8. void loop()
  9. {
  10. for(uint8_t t = 0; t < 5; t++)
  11. {
  12. uint8_t red = 32 * (1 + sin(t / 2.0 + j / 4.0) );
  13. uint8_t green = 32 * (1 + sin(t / 1.0 + f / 9.0 + 2.1) );
  14. uint8_t blue = 32 * (1 + sin(t / 3.0 + k / 14.0 + 4.2) );
  15. cyber.set_rgb(t, red, green, blue);
  16. }
  17. j += random(1, 6) / 6.0;
  18. f += random(1, 6) / 6.0;
  19. k += random(1, 6) / 6.0;
  20. delay(10);
  21. }

4. Light sensor

  1. #include "cyberpi.h"
  2. CyberPi cyber;
  3. void setup()
  4. {
  5. Serial.begin(115200);
  6. cyber.begin();
  7. }
  8. void loop()
  9. {
  10. Serial.print("light:");
  11. Serial.println(cyber.get_light());
  12. delay(500);
  13. }

5. Gyroscope

  1. #include "cyberpi.h"
  2. CyberPi cyber;
  3. void setup()
  4. {
  5. Serial.begin(115200);
  6. cyber.begin();
  7. }
  8. void loop()
  9. {
  10. Serial.print("roll:");
  11. Serial.print(cyber.get_roll());
  12. Serial.print(" pitch:");
  13. Serial.println(cyber.get_pitch());
  14. delay(25);
  15. }

6. Display

  1. #include "cyberpi.h"
  2. CyberPi cyber;
  3. void setup()
  4. {
  5. Serial.begin(115200);
  6. cyber.begin();
  7. for(int y=0;y<128;y++)
  8. {
  9. for(int x=0;x<128;x++)
  10. {
  11. int R = (128-x)*255/128;
  12. int G = x*255/128;
  13. int B = y*255/128;
  14. cyber.set_lcd_pixel(x,y,cyber.swap_color(cyber.color24_to_16((R<<16)+(G<<8)+B)));
  15. }
  16. }
  17. cyber.render_lcd();
  18. }
  19. void loop()
  20. {
  21. cyber.set_lcd_light(false);
  22. delay(2000);
  23. cyber.set_lcd_light(true);
  24. delay(2000);
  25. }

7. Points

  1. #include "cyberpi.h"
  2. CyberPi cyber;
  3. #define POINTS_COUNT 200
  4. Bitmap points[POINTS_COUNT];
  5. float speed_x[POINTS_COUNT];
  6. float speed_y[POINTS_COUNT];
  7. void setup() {
  8. Serial.begin(112500);
  9. delay(1000);
  10. cyber.begin();
  11. for(int i=0;i<POINTS_COUNT;i++)
  12. {
  13. points[i].x = 64;
  14. points[i].y = 64;
  15. speed_x[i] = random(100)/20.0f-2.5f;
  16. speed_y[i] = random(100)/20.0f-2.5f;
  17. points[i].width = 1;
  18. points[i].height = 1;
  19. points[i].buffer = (uint16_t*)cyber.malloc(2);
  20. points[i].buffer[0] = 0xffff;
  21. }
  22. }
  23. void loop()
  24. {
  25. cyber.clean_lcd();
  26. for(int i=0;i<POINTS_COUNT;i++)
  27. {
  28. cyber.set_bitmap(points[i].x,points[i].y,&points[i]);
  29. points[i].x+=speed_x[i];
  30. points[i].y+=speed_y[i];
  31. if(points[i].x<0||points[i].y<0||points[i].x>127||points[i].y>127)
  32. {
  33. points[i].x = 64;
  34. points[i].y = 64;
  35. }
  36. }
  37. cyber.render_lcd();
  38. }

8. Text

  1. #include "cyberpi.h"
  2. CyberPi cyber;
  3. uint8_t samples[128];
  4. int idx = 0;
  5. void setup()
  6. {
  7. Serial.begin(112500);
  8. delay(1000);
  9. cyber.begin();
  10. int font_size = 16;
  11. Bitmap *bitmap1 = cyber.create_text(L"你好",0xffff,font_size);
  12. cyber.set_bitmap(4,4,bitmap1);
  13. Bitmap *bitmap2 = cyber.create_text(L"簡體",0xff00,font_size);
  14. cyber.set_bitmap(4,24,bitmap2);
  15. Bitmap *bitmap3 = cyber.create_text(L"hello",0x00ff,font_size);
  16. cyber.set_bitmap(4,44,bitmap3);
  17. Bitmap *bitmap4 = cyber.create_text(L"こんにちは",0x0ff0,font_size);
  18. cyber.set_bitmap(4,64,bitmap4);
  19. Bitmap *bitmap5 = cyber.create_text(L"여보세요",0x0f0f,font_size);
  20. cyber.set_bitmap(4,84,bitmap5);
  21. Bitmap *bitmap6 = cyber.create_text(L"Привет",0xf0f0,font_size);
  22. cyber.set_bitmap(4,104,bitmap6);
  23. cyber.render_lcd();
  24. }
  25. void loop()
  26. {
  27. }

9. Loudness detection

  1. #include "cyberpi.h"
  2. CyberPi cyber;
  3. uint8_t samples[128];
  4. int idx = 0;
  5. void setup() {
  6. Serial.begin(112500);
  7. delay(1000);
  8. cyber.begin();
  9. }
  10. void loop()
  11. {
  12. if(idx<128)
  13. {
  14. samples[idx] = cyber.get_loudness()>>5;
  15. idx++;
  16. }
  17. else
  18. {
  19. for(int i=0;i<128;i++)
  20. {
  21. samples[i] = samples[i+1];
  22. }
  23. samples[idx-1] = cyber.get_loudness()>>5;
  24. }
  25. cyber.clean_lcd();
  26. for(int i=0;i<128;i++)
  27. {
  28. if(i==0)
  29. cyber.set_lcd_pixel(i,127-samples[i],0xffff);
  30. else
  31. {
  32. int min_level = MIN(samples[i-1],samples[i]);
  33. int max_level = MAX(samples[i-1],samples[i]);
  34. for(int j=min_level;j<=max_level;j++)
  35. {
  36. cyber.set_lcd_pixel(i,127-j,0xffff);
  37. }
  38. }
  39. }
  40. cyber.render_lcd();
  41. delay(25);
  42. }

10. Microphone data

  1. #include "cyberpi.h"
  2. CyberPi cyber;
  3. int lo[7] = {48,50,52,53,55,57,59};
  4. int mo[7] = {60,62,64,65,67,69,71};
  5. int ho[7] = {72,74,76,77,79,81,83};
  6. void mic_recv(uint8_t* samples,int len)
  7. {
  8. cyber.clean_lcd();
  9. for(int i=0;i<len;i+=8)
  10. {
  11. int current = (int8_t)samples[i+1];
  12. if(current>-64&&current<64)
  13. {
  14. cyber.set_lcd_pixel(i/8,current+64,0xffff);
  15. }
  16. }
  17. cyber.render_lcd();
  18. }
  19. void setup()
  20. {
  21. Serial.begin(112500);
  22. delay(1000);
  23. cyber.begin();
  24. cyber.on_microphone_data(mic_recv);
  25. for(int i=0;i<14;i++)
  26. {
  27. cyber.set_instrument(i);
  28. int idx = 0;
  29. while(idx<7)
  30. {
  31. cyber.set_pitch(0,lo[idx],100);
  32. delay(600);
  33. idx++;
  34. }
  35. idx = 0;
  36. while(idx<7)
  37. {
  38. cyber.set_pitch(0,mo[idx],100);
  39. delay(600);
  40. idx++;
  41. }
  42. idx = 0;
  43. while(idx<7)
  44. {
  45. cyber.set_pitch(0,ho[idx],100);
  46. delay(600);
  47. idx++;
  48. }
  49. }
  50. }
  51. void loop()
  52. {
  53. }

11. Music property

  1. #include "cyberpi.h"
  2. CyberPi cyber;
  3. int lo[7] = {48,50,52,53,55,57,59};
  4. int mo[7] = {60,62,64,65,67,69,71};
  5. int ho[7] = {72,74,76,77,79,81,83};
  6. void data_recv(uint8_t* samples,int len)
  7. {
  8. cyber.clean_lcd();
  9. for(int i=0;i<len;i+=16)
  10. {
  11. int current = samples[i+1];
  12. cyber.set_lcd_pixel(i/16,current-64,0xffff);
  13. }
  14. cyber.render_lcd();
  15. }
  16. void setup()
  17. {
  18. Serial.begin(112500);
  19. delay(1000);
  20. cyber.begin();
  21. cyber.on_sound_data(data_recv);
  22. for(int i=0;i<14;i++)
  23. {
  24. cyber.set_instrument(i);
  25. int idx = 0;
  26. while(idx<7)
  27. {
  28. cyber.set_pitch(0,lo[idx],100);
  29. delay(600);
  30. idx++;
  31. }
  32. idx = 0;
  33. while(idx<7)
  34. {
  35. cyber.set_pitch(0,mo[idx],100);
  36. delay(600);
  37. idx++;
  38. }
  39. idx = 0;
  40. while(idx<7)
  41. {
  42. cyber.set_pitch(0,ho[idx],100);
  43. delay(600);
  44. idx++;
  45. }
  46. }
  47. }
  48. void loop()
  49. {
  50. }